C Programming MCQ – Array

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
advertisement
advertisement

b)

hell, hell
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

c)

hell, hello

d) Runtime Error
View Answer

Answer: b
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”.
 
 

advertisement

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

Answer: c
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

Answer: c
Explanation: None.
advertisement

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

Answer: d
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

Answer: b
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

Answer: c
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

Answer: c
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

Answer: d
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
Answer: d
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

Answer: b
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

Answer: c
Explanation: None.

More Array MCQs in C Programming:

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.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.