ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
char *words[] = {"bat", "cat", "rat", "mat"};
char **p = words + 1;
char **q = words + 3;
printf("%ld", (long)(q - p));- A. 2
- B. 16
- C. 4
- D. 1
Correct answer: A. 2
Pointer subtraction between two char** values yields the number of char* ELEMENTS between them, not bytes: q-p = (words+3)-(words+1) = 2.
More C Programming questions
- What is printed? (This program has no undefined behavior.) c char fmt(int n) { static char buf[16]; sprintf(buf, "%d", n); return buf; }…
- What is printed? Assume a 64-bit LP64 ABI (4-byte int). c int a[3][2] = {{1,2},{3,4},{5,6}}; int (p)[2] = a; p = p + 2; printf("%ld %d"…
- Which statement about this code is correct? c int add(int a, int b) { return a + b; } int main(void) { int (fp)(int) = (int ()(int))add…
- What is printed? c int a[3] = {1,2,3}; int parr[3] = {a, a+1, a+2}; int pp = parr; (pp + 1) += 10; printf("%d %d %d", a[0], a[1], a[2]);
- What is printed? c typedef int (Op)(int,int); int a(int x,int y){ return x+y; } int b(int x,int y){ return x-y; } Op table[2] = {a, b}…
- What is printed? c int a[2][3] = {{1,2,3},{4,5,6}}; int rowptrs[2] = {a[0], a[1]}; int pp = rowptrs; for (int i = 0; i < 2; i++) for (int…