1. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
int ary[4] = {1, 2, 3, 4};
-
printf("%dn", *ary);
-
}
a) 1
b) Compile time error
c) Some garbage value
d) Undefined variable
Answer
Answer: a [Reason:] None.
2. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
const int ary[4] = {1, 2, 3, 4};
-
int *p;
-
p = ary + 3;
-
*p = 5;
-
printf("%dn", ary[3]);
-
}
a) 4
b) 5
c) Compile time error
d) 3
Answer
Answer: b [Reason:] None.
3. Different ways to initialize an array with all elements as zero are
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
Answer
Answer: d [Reason:] None.
4. The elements in the array of the following code are
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
Answer
Answer: b [Reason:] None.
5. 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
Answer
Answer: c [Reason:] None.
6. An array of similar data types which themselves are collection of dissimilar data type are
a) Linked Lists
b) Trees
c) Array of Structure
d) All of the mentioned
Answer
Answer: c [Reason:] None.
7. Comment on an array of 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
Answer
Answer: d [Reason:] None.
8. What is the output of the code given below?
-
#include <stdio.h>
-
int main()
-
{
-
int ary[4] = {1, 2, 3, 4};
-
int p[4];
-
p = ary;
-
printf("%dn", p[1]);
-
}
a) 1
b) Compile time error
c) Undefined behaviour
d) 2
Answer
Answer: b [Reason:] None.