ProgrammingHardProduct company OA
What is printed?
What is printed?
void move(int **pp) { (*pp)++; **pp += 10; }
int main(void) {
int a[] = {1, 2, 3};
int *p = a;
move(&p);
move(&p);
printf("%d %d %d %td", a[0], a[1], a[2], p - a);
}- A. 11 12 3 2
- B. 1 12 3 1
- C. 1 12 13 0
- D. 1 12 13 2
Correct answer: D. 1 12 13 2
Passing &p lets move change the caller's p. Each call first advances p, then adds 10 to the element it now points at: a[1] = 12, then a[2] = 13, and p ends at a + 2. '… 0' assumes the pointer was passed by value.
More C Programming questions
- Assume 32-bit unsigned int. What is printed? c unsigned x = 0xABCD; printf("%X %X", (x >> 4) & 0xF, (x & ~(0xFu << 8)) | (0x3u << 8));
- In C99, which declaration lets you allocate a rows × cols matrix of int (cols known at run time) with ONE malloc, use it as m[i][j], and…
- With 4-byte int, what is printed? c int a[4]; memset(a, 1, sizeof a); printf("%d", a[0]);
- What is printed? c struct N { int v; struct N nx; }; struct N c = {3, NULL}, b = {2, &c}, a = {1, &b}; struct N prev = NULL, cur = &a, nx…
- After this code, what does buf hold and what is n? c char buf[20]; int n = sprintf(buf, "%04d|%.2s", 7, "xyz");
- What is printed? c int c = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if (j == i) continue; if (j > i + 1) break; c++…