ProgrammingHardTCS NQT · Infosys
int a[5] = {10, 20, 30, 40, 50}; int *p = a + 1, *q = a + 4; printf("%td %d", q - p, *(p + 2)); prints what?
- A. 3 40
- B. 4 50
- C. 3 30
- D. 2 40
Correct answer: A. 3 40
Subtracting two pointers into the same array gives the element distance, here 4 - 1 = 3. p + 2 points to a[3], which holds 40.
More C Programming questions
- void f(int a[10]) { printf("%zu", sizeof a); } Which statement about the result is correct?
- int m[2][3] = {{1, 2, 3}, {4, 5, 6}}; int (p)[3] = m; printf("%d", ((p + 1) + 2)); prints what?
- Which statement about sizeof is correct when x is an int variable initialised to 5?
- char s[] = "hello"; printf("%zu %zu", sizeof s, strlen(s)); prints what?
- char names[] = {"ab", "cde", "f"}; What is strlen(names[0]) strlen(names[1]) + strlen(names[2])?
- int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int (ops[])(int, int) = {add, sub, add}; int r = 10; for…