• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

HW Help! C programming

bleeb

Lifer
Question: Given:

int myArray[] = {1, 3, 5, 7, 11, 13, 17}, *p;
p = myArray;

Which expressions evaluate to 11??

1. p[4]
2. *(p+4)
3. *(myArray + 4)
4. *p[4]
5. (myArray + 4)
6. myArray[4]

Please explain your answers. Thanks!
 
1 2 3 6

if you are not sure of the reason for a particular one ask.

single dimentional arrays are pointers, so *p is of the same type as myArray. it's assigned to the same address as the array pointed to by myArray so myArray is exactly the same as p.

p[4] - self explanatory
*(p+4) - you take the address of the first item, add 4 to it to get the address of the 5th item, then dereference the pointer to get the 5th item
*(myArray + 4) - same as 2
p[4] - same as 1
 
Back
Top