Anasayfa
/
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

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

Çözüm

4 (283 Oylar)
Zübeyde
Uzman doğrulaması
Elit · 8 yıl öğretmeni

Cevap

a) To access the element at index 4 using the pointer variable `p`, you can use the following statement:```cppint value = *p + 4;```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.b) To assign the address of the third element of `stuff` to the pointer `q`, you can use the following statement:```cppq = &stuff[2];```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`.