Module-3
1. How do you initialize an array in C?
a) int arr[3] = (1,2,3);
b) int arr(3) = {1,2,3};
c) int arr[3] = {1,2,3};
d) int arr(3) = (1,2,3);
Answer: c
2. Assuming int is of 4bytes, what is the size of int arr[15];?
a) 15
b) 19
c) 11
d) 60
Answer: d
3. In general, the index of the first element in an array is __________
a) 0
b) -1
c) 2
d) 1
Answer: a
4. What will be the output of the program ?
#include<stdio.h>
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
A. 2, 1, 15
B. 1, 2, 5
C. 3, 2, 15
D. 2, 3, 20
Answer: Option C
5. Is there any difference int the following declarations?
int fun(int arr[]);
int fun(int arr[2]);
A. Yes
B. No
Answer: Option B
6. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. char *str = "hello, world";
5. char *str1 = "hello, world";
6. if (strcmp(str, str1))
7. printf("equal");
8. else
9. printf("unequal");
10. }
a)equal
b) unequal
c)Compilation error
d) Depends on the compiler
Answer: b
7. Strcat() function adds null character.
a) Only if there is space
b) Always
c) Depends on the standard
d) Depends on the compiler
Answer: b
8. What will strcmp() function do?
a) compares the first n characters of the object
b) compares the string
c) undefined function
d) copies the string
Answer: b
9. The ______ function appends not more than n characters.
a) strcat()
b) strcon()
c) strncat()
d) memcat()
Answer: c
[Link] is the header file used to call String handling functions?
a)math.h
b)string.h
c)stdio.h
d)stdlib.h
Answer:b