ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
int a[6] = {1,2,3,4,5,6};
int *p = a + 1;
int *q = a + 4;
int diff = q - p;
q -= diff / 3 * 2;
printf("%d %d", diff, *q);- A. 3 2
- B. 3 4
- C. 4 3
- D. 3 3
Correct answer: D. 3 3
diff = (a+4)-(a+1) = 3. diff/3*2 = 1*2 = 2 (integer division first: 3/3=1, then *2=2). q -= 2 moves q from a+4 to a+2, so *q = a[2] = 3.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c int a[3][2] = {{1,2},{3,4},{5,6}}; int (p)[2] = a + 1; int q = (int)p; q++; printf("%d %d"…
- What is printed? c int a[3] = {5,10,15}; int p = a; int q = &a[2]; while (p != q) { printf("%d ", p); p++; } printf("%d", p);
- What is printed? c int a[3] = {1,2,3}; int p = a; int arrp[1] = {p}; int pp = arrp; (pp)[1] = 99; printf("%d %d %d", a[0], a[1], a[2]);
- What is printed? c int a[3] = {1,2,3}; int p = &a[1]; int x = p[1] - p[-1]; int y = (p+1) - (p-1); printf("%d %d", x, y);
- What is printed? c int add(int a,int b){ return a+b; } int sub(int a,int b){ return a-b; } int mul(int a,int b){ return ab; } int…
- What is printed? Assume a 64-bit LP64 ABI (4-byte int) and that the matrix is stored contiguously. c int a[2][3] = {{1,2,3},{4,5,6}}; int…