Quiz On c5
Quiz On c5
a) In the first statement 7 specifies a particular element, whereas in the second statement it
specifies a type;
b) In the first statement 7 specifies a particular element, whereas in the second statement it
specifies the array size.
c) In the first statement 7 specifies the array size, whereas in the second statement it specifies a
particular element of array.
d) In both the statement 7 specifies array size.
Solution: (c) The statement 'c' is correct, because int num[7]; specifies the size of array
and num[7]=8; designates the particular element(8th element) of the array.
4. Which of the following is correct statement to access 10th element in a array arr[] of size 30?
a) arr[10]
b) arr[9]
c) arr{10}
d) arr{9}
Solution: (b) arr[9] is the correct syntax to access the 10th element, as in C index starts from 0.
b) No
c) May be
d) Depends on compiler
Solution: (b) After assignment of an array, the elements can’t be deleted or new element can’t be added.
7. An 1 dimensional integer array of size 10 is declared in a C program. The memory location of the first byte
of the array is 1050. What will be the location of the 9th element of the array? (Assuming an integer takes 2
bytes of memory)
a) 1066
b) 1084
c) 1068
d) 1064
Solution: (a) Integer takes two bytes of memory. As the memory assignment to the elements are consecutive and the
index starts from 0, the 9th element will be located at 1050+(8×2) =1066.
Solution: (d) The size of the array does not match with the dimension of the array. Thus the compiler will show error.
Solution: (b)
Please follow the operator precedence table and compute the values of each step. The answer will come as
1,2,2
#include<stdio.h>
int main()
{
int i;
int arr[3] = {1};
for (i = 0; i < 3; i++)
printf("%d ", arr[i]);
return 0;
}
a) 1 followed by garbage values
b) 1 1 1
c) 1 0 0
d) Syntax error
Solution: (c)
If array is initialized with few elements, remaining elements will be initialized to 0. Therefore, 1 followed
by 0, 0, will be printed.
13. While passing an array as an argument to a function, which of the following is actually passed to the
function?
a) Array size
b) First element of the array
c) Last element of the array
d) Base address of the array
WEEK 6 ASSIGNMENT SOLUTION
Solution: (d) The base address of the array is passed to the function as an argument.
a) 1,2,3
b) 5,6,7
c) 5,7,9
d) Error