1) What is an Array in C language.?
A) A group of elements of same data type.
B) An array contains more than one element
C) Array elements are stored in memory in continuous or contiguous locations.
2) Choose a correct statement about C language arrays.
A) An array address is the address of first element of array itself.
B) An array size must be declared if not initialized immediately.
C) Array size is the sum of sizes of all elements of the array.
3) What are the Types of Arrays.?
A) int, long, float, double
4) An array Index starts with.?
A) -1
5) Choose a correct statement about C language arrays.
A) An array size can not changed once it is created.
B) Array element value can be changed any number of times
C) To access Nth element of an array students, use students[n-1] as the starting index is 0.
6) What is the output of C Program.? int main() { int a[]; a[4] = {1,2,3,4}; printf("%d", a[0]); }
A) 1
Explanation:
If you do not initialize an array, you must mention ARRAY SIZE.
7) What is the output of C Program.? int main() { int a[] = {1,2,3,4}; int b[4] = {5,6,7,8}; printf("%d,%d", a[0], b[0]); }
A) 1,5
Explanation:
It is perfectly allowed to skip array size if you are initializing at the same time. a[0] is first element.
int a[] = {1,2,3,4};
8) What is the output of C Program.? int main() { char grade[] = {'A','B','C'}; printf("GRADE=%c, ", *grade); printf("GRADE=%d", grade); }
A) GRADE=some address of array, GRADE=A
B) GRADE=A, GRADE=some address of array
Explanation:
Variable grade = address of first element. *grade is the first element of array i.e grade[0].
9) What is the output of C program.? int main() { char grade[] = {'A','B','C'}; printf("GRADE=%d, ", *grade); printf("GRADE=%d", grade[0]); }
A) A A
Explanation:
*grade == grade[0]. We are printing with %d not with %c. So, ASCII value is printed.
10) What is the output of C program.? int main() { float marks[3] = {90.5, 92.5, 96.5}; int a=0; while(a<3) { printf("%.2f,", marks[a]); a++; } }
A) 90.5 92.5 96.5
Explanation:
0.2%f prints only two decimal points. It is allowed to use float values with arrays.
11) What is the output of C Program.? int main() { int a[3] = {10,12,14}; a[1]=20; int i=0; while(i<3) { printf("%d ", a[i]); i++; } }
A) 20 12 14
Explanation:
a[i] is (i+1) element. So a[1] changes the second element.
12) What is the output of C program.? int main() { int a[3] = {10,12,14}; int i=0; while(i<3) { printf("%d ", i[a]); i++; } }
A) 14 12 10
Explanation:
a[k] == k[a]. Use any notation to refer to array elements.
13) What is the output of C Program.? int main() { int a[3] = {20,30,40}; a[0]++; int i=0; while(i<3) { printf("%d ", i[a]); i++; } }
A) 20 30 40
Explanation:
You can use increment and decrement operators on array variables too.
14) What is the output of C program with arrays.? int main() { int a[3] = {20,30,40}; int b[3]; b=a; printf("%d", b[0]); }
A) 20
C) address of 0th element.
Explanation:
You can assign one array variable to other.
15) What is the output of C Program with arrays and pointers.? int main() { int a[3] = {20,30,40}; int (*p)[3]; p=&a; printf("%d", (*p)[0]); }
A) 20
Explanation:
You can not directly assign one array variable to other. But using an array pointer, you can point to the another array. (*p) parantheses are very important.
16) What is the output of C program with arrays and pointers.? int main() { int a[3] = {20,30,40}; int *p[3]; p=&a; printf("%d", *p[0]); }
A) 20
Explanation:
To point to an array, array pointer declaration should be like (*p)[3] with parantheses. It points to array of 3 elements.
17) What is the output of C program with arrays and pointers.? int main() { int a[3] = {20,30,40}; printf("%d", *(a+1)); }
A) 20
Explanation:
*(a+0) == *a == a[0]. So *(a+1) is element at index 1. Index starts with ZERO.
18) What is an array Base Address in C language.?
A) Base address is the address of 0th index element.
B) An array b[] base address is &b[0]
C) An array b[] base address can be printed with printf("%d", b);
19) What is the output of C Program with arrays and pointers.? void change(int[]); int main() { int a[3] = {20,30,40}; change(a); printf("%d %d", *a, a[0]); } void change(int a[]) { a[0] = 10; }
A) 20 20
Explanation:
Notice that function change() is able to change the value of a[0] of main(). It uses Call By Reference. So changes in called function affected the original values.
20) An entire array is always passed by ___ to a called function.
A) Call by value