Ana sayfa
/
Teknoloji
/
int stuff[10] =(1,4,5 ,7,8,9); int *p; int *q p=stuff Consider the code above. a) Write a statem ent using pointer variable p, that would be equivalent to s tuffl 4] b) Write a statement that would assign the address of the third element of s tuff to pointer q

Soru

int stuff[10] =(1,4,5 ,7,8,9);
int *p;
int *q
p=stuff
Consider the code above.
a) Write a statem ent using pointer variable
p, that would be equivalent to s tuffl 4]
b) Write a statement that would assign the
address of the third element of s tuff to
pointer q

int stuff[10] =(1,4,5 ,7,8,9); int *p; int *q p=stuff Consider the code above. a) Write a statem ent using pointer variable p, that would be equivalent to s tuffl 4] b) Write a statement that would assign the address of the third element of s tuff to pointer q

Çözüm

4.0283 Voting
avatar
Zübeyde
Elit · 8 yıl öğretmeni
Uzman doğrulaması

Cevap

a) To access the element at index 4 using the pointer variable `p`, you can use the following statement:<br />```cpp<br />int value = *p + 4;<br />```<br />This statement calculates the address of the element at index 4 by adding 4 to the base address stored in `p` and then dereferences the resulting pointer to get the value.<br /><br />b) To assign the address of the third element of `stuff` to the pointer `q`, you can use the following statement:<br />```cpp<br />q = &stuff[2];<br />```<br />This statement calculates the address of the third element of `stuff` by adding 2 times the size of an integer to the base address of `stuff` and then stores the resulting address in `q`.
Derecelendirmek için tıklayın: