C Arrays and Strings-3
1. Choose a correct statement about C String.
a) A string is a group of characters enclosed by double quotes
b) If a string is defined with double quotes, NULL is automatically added at the end
c) Size of a string is without counting NULL character at the end
d) All the above
Answer: D
No explaination is given for this question.
2. A C string elements are always stored in?
a) Random memory locations
b) Alternate memory locations
c) Sequential memory locations
d) None of the above
Answer: C
No explaination is given for this question.
3. An array elements are always stored in ______ memory locations.
a) Random
b) Sequential
c) Sequential and Random
d) None of the above
Answer: A
No explaination is given for this question.
4. Let x be an array. Which of the following operations are illegal?
I. ++x
II. x+1
III. x++
IV. x*2
a) I and II
b) I, II and III
c) II and III
d) I, III and IV
Answer: D
No explaination is given for this question.
5. What is the maximum number of dimensions an array in C may have?
a) 2
b) 3
c) 12
d) No Limit
Answer: D
There is no practical limits for dimensions of array, the only practical limits are memory size and compilers.
6. Is there any function declared as strstr()?
a) true
b) False
Answer: A
No explaination is given for this question.
7. The______ function returns a pointer to the first character of a token.
a) strstr()
b) strcpy()
c) strspn()
d) strtok()
Answer: D
The strtok() function returns a pointer to the first character of a token, if there is no token then a null pointer is returned.
8. Which of the given function is used to return a pointer to the located character?
a) strrchr()
b) strxfrm()
c) memchar()
d) strchar()
Answer: D
The strchr() function is used to return a pointer to the located character if character does not occur then a null pointer is returned.
9. The______ function returns the number of characters that are present before the terminating null character.
a) strlength()
b) strlen()
c) strlent()
d) strchr()
Answer: B
The strlen() function is used to return the number of characters that are present before the terminating null character.
10. What will be the output of the program if the array begins at 1000 and each integer occupies 2 bytes?
void main() {
int arr[2][2] = { 1, 2, 3, 4};
printf("%u, %u", arr+1, &arr+1);
}
a) 1004 1008
b) 1002 1008
c) 1002 1002
d) 1008 1002
Answer: A
For a two-dimensional array like a reference to array has type "pointer to array of 2 ints". Therefore, arr+1 is pointing to the memory location of first element of the second row in array i.e 1000 + 2*2 = 1004. &arr has type "pointer to array of 2 arrays of 2 ints", totally 4 ints. Therefore, &a+1 denotes 1000 + 4*2 = 1008.