This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Arrays”.
Pre-requisite for C Arrays MCQ set: Video Tutorial on C Arrays.
1. What will be output of the following C code where we copy an array ‘a’ into array ‘b’ and then the array ‘b’ into ‘a’?
#include<stdio.h> #include<string.h> main() { char a[] = "hell"; char b[] = "hello"; strcpy(b, a); strcpy(a, b); printf("%s, %s", a, b); }
a)
hello, hello
b)
hell, hell
c)
hell, hello
d) Runtime Error
View Answer
Explanation: In the above code, we are copying first the content of array a into array b. So, “hell” gets copied to array b. After that we are copying the content of array b into array a. Since, array b contained the string “hell” now, it gets copied to array a. Hence, the final answer will be “hell, hell”.
2. Which keyword is used to make the array size optional in C language during array declaration?
a) auto
b) static
c) extern
d) register
View Answer
Explanation: None.
3. Which of the following is the correct syntax to send an array as a parameter to a C function?
a) Both func(&array) and func(*array);
b) Both func(#array) and func(&array);
c) Both func(array) and func(&array);
d) Both func(array[size]) and func(*array);
View Answer
Explanation: None.
4. What are the different ways to initialize an array with all elements as zero?
a) int array[5] = {};
b) int array[5] = {0};
c)
int a = 0, b = 0, c = 0; int array[5] = {a, b, c};
d) All of the mentioned
View Answer
Explanation: None.
5. What are the elements present in the array of the following C code?
int array[5] = {5};
a) 5, 5, 5, 5, 5
b) 5, 0, 0, 0, 0
c) 5, (garbage), (garbage), (garbage), (garbage)
d) (garbage), (garbage), (garbage), (garbage), 5
View Answer
Explanation: None.
6. Which of the following declaration is illegal?
a)
int a = 0, b = 1, c = 2; int array[3] = {a, b, c};
b)
int size = 3; int array[size];
c)
int size = 3; int array[size] = {1, 2, 3};
d) All of the mentioned
View Answer
Explanation: None.
7. An array of similar data types which themselves are a collection of dissimilar data type are ___________
a) Linked Lists
b) Trees
c) Array of Structure
d) All of the mentioned
View Answer
Explanation: None.
8. Comment on an array of the void data type.
a) It can store any data-type
b) It only stores element of similar data type to first element
c) It acquires the data type with the highest precision in it
d) You cannot have an array of void data type
View Answer
Explanation: None.
9. An array in C cannot be initialized by which of the following statement?
a) char a[] = “Hello”;
b) char a[6] = {};
c) char a[6] = {0};
d)
char a[6]; a = "Hello";View Answer
Explanation: None.
10. What is the data type of the array passed from the command line into the main() function in C?
a) char arr[];
b) char *arr[];
c) char **arr[];
d) char arr[][];
View Answer
Explanation: None.
11. Which of the following c statement will calculate the correct size of an array of 10 integers?
(Assuming the declaration as int a[10];)
a) sizeof(a[10]);
b) sizeof(*a);
c) sizeof(a);
d) sizeof(&a);
View Answer
Explanation: None.
More Array MCQs in C Programming:
- Multidimensional Arrays – 1
- Multidimensional Arrays – 2
- Arrays of Structures – 1
- Arrays of Structures – 2
- Initialization of Pointer Arrays – 1
- Initialization of Pointer Arrays – 2
- Pointers Vs. Multi-dimensional Arrays – 1
- Pointers Vs. Multi-dimensional Arrays – 2
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for Computer Science Internship
- Practice Computer Science MCQs
- Check C Books
- Apply for C Internship
- Watch Advanced C Programming Videos