GATE Computer ScienceModerateNIELIT · GATE CSE
int a[6] = {2, 4, 6, 8, 10, 12}; int *p = a + 1, *q = a + 5; What does printf("%ld %d", (long)(q - p), *(p + (q - p) / 2)); print?
- A. 4 8
- B. 4 6
- C. 5 8
- D. 4 10
Correct answer: A. 4 8
q − p = 4 elements; p + 2 = a + 3, whose value is 8.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int f(int n) { if (n < 2) return 1; return f(n - 1) + f(n - 2); } Including the initial call, how many times is f invoked while evaluating…
- A queue is implemented with two stacks: ENQ pushes onto stack S1; DEQ pops from S2, and if S2 is empty it first moves every element of S1…
- A BST is built by inserting 50, 30, 70, 20, 40, 60, 80, 35, 45 in this order. How many nodes lie in the right subtree of the node 30?
- int f(int n) { static int c = 0; c = c 2 + n; return c; } int main() { int a = f(1); int b = f(2); int d = f(3); int e = f(4)…
- void p(int n) { if (n <= 0) return; printf("%d ", n); p(n - 2); p(n - 3); printf("%d ", n); } What does p(6) print?
- int count(unsigned x) { int c = 0; while (x) { x &= (x - 1); c++; } return c; } What is the value of count(0xB5D)?