Array Question Bank
1. Consider the code: int a[5] = {1, 2}; printf("%d", a[3]); What is the output?
A) 2
B) 1
C) 0
D) Garbage Value
2. What happens if we access an array element out of bounds in C?
(GATE-2014)
A) Compile-time error
B) Runtime error always
C) Garbage value or undefined behavior
D) Program terminates immediately
3. What is the output? int a[5] = {1,2,3,4,5}; printf("%d", *(a + 2));
A) 1
B) 2
C) 3
D) 4
4. What is the output? int a[3] = {1,2,3}; printf("%d", sizeof(a));
A) 3
B) 4
C) 8
D) 12
5. What will be the output? int a[3] = {10,20,30}; printf("%d", *(&a; + 1) - a);
(GATE-2016)
A) 1
B) 2
C) 3
D) Undefined
6. Which operation is NOT allowed on an array name in C?
A) a + 1
B) a++
C) *(a + 1)
D) a[i]
7. Let int a[10]; What is the type of a?
A) int*
B) int[10]
C) pointer to int
D) pointer to array of 10 int
8. Which difference between arrays and pointers is fundamental?
A) Arrays use heap, pointers use stack
B) Arrays store data, pointers store addresses
C) Arrays support pointer arithmetic, pointers do not
D) Arrays can be incremented, pointers cannot
9. Which of the following fundamentally prevents resizing an array in C?
A) Fixed memory allocation model of C
B) Absence of garbage collection
C) Lack of built-in bounds checking
D) Contiguous memory requirement
10. What would be the output of int a[] = {1,2,3}; printf("%d", sizeof(a)/sizeof(*a));
A) 3
B) 4
C) 8
D) Compilation error
11. What is the output? int a[5]={1,2,3,4,5}; int *p=(int*)(&a;+1); printf("%d", *(p-1));
(GATE-2012)
A) 1
B) 4
C) 5
D) Undefined
12. What will be printed? int a[4]={10,20,30,40}; int (*p)[4]=&a; printf("%d", (*p)[2]);
(GATE-2013)
A) 10
B) 20
C) 30
D) 40
13. Which statement is TRUE?
(GATE-2015)
A) sizeof(a) gives pointer size in main
B) a can be incremented
C) &a;+1 moves by entire array
D) a=&a;[0] is valid
14. What is the output? int a[]={1,2,3,4}; printf("%d", *(a + *(a+1)));
(GATE-2017)
A) 2
B) 3
C) 4
D) 5
15. What will be printed? int a[3][3]={{1,2,3},{4,5,6},{7,8,9}}; printf("%d", *(*(a+1)+*(a[0])));
(GATE-2018)
A) 4
B) 5
C) 6
D) 7
16. What is the output? int a[]={2,4,6}; printf("%d", *(a + sizeof(a)/sizeof(int) - 1));
(GATE-2019)
A) 2
B) 4
C) 6
D) Undefined
17. Which declaration allows accessing a 2D array inside a function?
(GATE-2020)
A) void f(int **a)
B) void f(int a[][])
C) void f(int a[][5])
D) void f(int *a[5])
18. What is printed? int a[]={1,2,3}; int *p=a; printf("%d", *p++ + *p);
(GATE-2021)
A) 2
B) 3
C) 4
D) Undefined
19. What will be the output? int a[5]={1,2,3,4,5}; printf("%d", *(a + 1[*a]));
(GATE-2022)
A) 2
B) 3
C) 4
D) 5
20. Which expression refers to the same location as a[i][j] in a 2D array?
(GATE-2023)
A) *(a+i+j)
B) *(*(a+i)+j)
C) *(a+(i+j))
D) *(a[i]+j)
Answer Key
1. C
2. C
3. C
4. D
5. C
6. B
7. B
8. B
9. D
10. A
11. C
12. C
13. C
14. C
15. C
16. C
17. C
18. B
19. D
20. B