Chapter 10
1: | What will this program print?#include <stdio.h> int main(void) { int ref[] = {8, 4, 0, 2}; int *ptr; int index; for (index = 0, ptr = ref; index < 4; index++, ptr++) printf("%d %d\n", ref[index], *ptr); return 0; } |
A1: | The printout is this:
8 8 4 4 0 0 2 2 |
2: | In question 1, how many elements does ref have? |
A2: | The array ref has 4 elements because that is the number of values in the initialization list. |
3: | In question 1, ref is the address of what? What about ref + 1? What does ++ref point to? |
A3: | The array name ref points to the first element of the array, the integer 8. The expression ref + 1 points to the second element, the integer 4. The construction ++ref is not a valid C expression; ref is a constant, not a variable. |
4: | What ... |
Get C Primer Plus, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.