C Array Questions and Answers
Arrays in C language form the foundation of data storage and manipulation. They store multiple values of the same type under a single variable name, allowing efficient data handling. Programming questions and answers related to arrays frequently appear in campus placement exams and coding interviews by TCS, Wipro, and Capgemini. This topic includes C array questions with answers covering array declaration, initialization, multidimensional arrays, and pointer relations. Practicing these problems will enhance your understanding of indexing, memory usage, and algorithm design for real-world applications.
C Array
Showing 10 of
108 questions
32. Find the output void main () { int array [ ] ={1, 3, 5, 7, 9}, *p, i; p=array [0]; for (i=0; i<5; i++) printf("%2d", ++*p); }
- 2 3 4 5 6
- 1 3 5 7 9
- 1 2 3 4 5
- 1 2 3 4 5 Null pointer assignment
33. This is a small program to find the maximum element in an array. How many comparisons in the below function to find the maximum element. int findmax (int A[ ], int n) { int max, i; max=A[0]; for (i=1; i<n; i++) if (A[i] >max) max =A[i]; return max ; }
- n-1
- n+1
- n/2
- n
34. Find the output void main ( ) int a[5]; a[-2]=5; a[2]=1; printf("%d", -2[a]); }
- 5
- -1
- Memory dump
- None of these
35. Find the output void main () [ int a[ ] ={1, 2, 3, 4, 5}, *p,*q; p=a; q=a; if (*p++==++*q) printf("Equal"); else printf("Not equal"); }
- Equal
- Not equal
- Compilation error
- None of these
36. Find the output void main () { int *p, a[5]={1, 2, 3, 4, 5} p=a; printf("%d %d %d", ++*p, ++*p); }
- 1 2 3
- 3 2 1
- 3 3 2
- None of these
37. Find the output void main( ) { int a[]={{1+2}, {3+4}, {5+6}}, i; for (i=0; i<3; i++) printf("%2d",a[1]); }
- 3 7 11
- 2 4 6
- 1 3 5
- Compilation error
38. Find the output int arr [ ]={1, 2, 3}; void main ( ) { int a, *p, b, c; a=51 %26; p=&a; a+=2; b=arrr[1]+a; c=*p+b; printf("%d %d %d", a, b, c); }
- 25 27 52
- 27 29 54
- 27 28 53
- 27 29 56
39. Find the output void main ( ) { int a[ ]={0, 0, 0, 0, 0, }, *p, i; p=a; for (i=0; i<5; i++) printf("%2d", ++*p+a [i]); }
- 1 2 3 4 5
- 2 2 3 4 5
- 1 1 1 1 1
- None of these
40. Find the output void main ( ) { int a [ ] [4]= {1, 2, 3, 4, 5, 6, 7, 8}; int (*p) [4]=a; printf("%d %d", (*p+1)[1], (*p) [2]); p++; printf("%d %d", (*%d %d", (*p+2) [0], (*p)[2]); }
- 2356
- 2256
- 3366
- 3377