HOW would i do this? NAME: 1. Given the following declarations: int 6, 7, 5); ar
ID: 3606647 • Letter: H
Question
HOW would i do this?
NAME: 1. Given the following declarations: int 6, 7, 5); arr [5] = {2, 4, *p = Garr [1] ; int Also assume that the address of the first element of the array arr is xi, the address of the second element is x2, etc Give the value of each of the following identifiers (answer each question using the original values declared above): a) p b) p f) (p+3) 2. Given the following declaration: float angle [10] Which of the following statements would be legal assignments in C? a) float p = angle [3]; b) float p= angle; c) float *p= angle [0]; d) float *p= angle; e) float *p= ∠ [7];Explanation / Answer
1)
int arr[5] = {2,4,6,7,5};
int *p = &arr[1];
*p // 4 (value at address of index 1)
p // x2
*(++p) // 6 (value at next address)
++p // x3 (move pointer to next address)
++(*p) // 5 (4+1) (increment value at next address)
cout << *(p+3) << endl; // 5 (incremnt address by 3.)
2)
float angle[10];
float p = angle[3]; // valid
float p = angle; // could not convert address to value
float *p = angle[0]; // could not assign value to pointer.
float *p = angle; // valid
float *p = &angle[7]; // valid
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.