GATE Computer ScienceHardGATE CS (PYQ pattern)
Assume 4-byte int and 8-byte pointers. char s[] = "ab\0cd"; char *p = "ab\0cd"; int a[3][4]; printf("%zu %zu %zu %zu %zu", sizeof(s), sizeof(p), strlen(s), sizeof(a[1]), sizeof(*a) / sizeof(**a)); What is printed?
- A. 5 8 2 16 4
- B. 6 8 2 16 4
- C. 6 8 2 4 4
- D. 6 8 5 16 12
Correct answer: B. 6 8 2 16 4
s has 5 characters plus the terminating zero = 6; p is a pointer = 8; strlen stops at the embedded '\0' = 2; a[1] is a row of 4 ints = 16; *a is a row (16 bytes) and **a an int (4), ratio 4.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- For a BST built from distinct keys (deletion of a node with two children uses its inorder successor), consider: I. Inserting a new key and…
- A directed graph has adjacency lists (visited in the order listed): A: B, C; B: D, E; C: E, F; D: G; E: D, H; F: H, B; G: none; H: G, A…
- A DAG on vertices 1..7 has edges 1->2, 1->3, 2->4, 3->4, 3->5, 4->6, 5->6, 7->5. How many distinct topological orderings does it have?
- Union-find on elements 1..12 (initially separate) uses union by size (the root of the larger set becomes the parent; on a tie the root of…
- A 3-ary max-heap with 100 elements is stored in a 0-indexed array (the children of i are 3i + 1, 3i + 2, 3i + 3). How many leaves does it…
- Build-heap (bottom-up, max-heap) is run on [3, 9, 2, 1, 4, 5, 8, 7, 6, 10, 12, 11]. In each sift-down step the larger of the element and…