How many times will the following loop execute?
int arr[5]; for(int i=0; i<5; i++) arr[i]=0;
Answer: B
Loop runs from i=0 to i=4, executing 5 times total. All array elements are initialized to 0.
Q.22Easy
In C, when you declare an array like int arr[10], what does the array name 'arr' represent?
Answer: A
Array names decay to pointers to their first element in most contexts. 'arr' is equivalent to &arr[0] and cannot be reassigned.
Q.23Easy
What is the size of the string 'Hello' when stored in a character array with null terminator?
Answer: B
'Hello' has 5 characters plus 1 null terminator (\0), making total 6 bytes.
Q.24Easy
Which of the following correctly initializes a 2D array of integers?
Answer: A
Option A is valid - 2D arrays can be initialized with all elements in a single brace. Options B and C are invalid as at least one dimension must be specified.
Q.25Easy
In the declaration char *str[5], what does the array represent?
Answer: A
The syntax char *str[5] declares an array of 5 pointers, each pointing to a character (or string). The brackets bind tighter than asterisk.
Advertisement
Q.26Easy
How many elements can be stored in a 2D array declared as int matrix[4][5]?
Answer: D
A 2D array with dimensions [4][5] contains 4 × 5 = 20 elements total.
Q.27Easy
What is the correct way to declare and initialize a string in C?
Answer: B
Option B shows two valid ways: pointer to string literal or character array. Option A is wrong (single char), C is wrong (no String type in C).
Q.28Easy
What is the output of: int arr[] = {10, 20, 30}; printf("%d", *(arr+1));?
Answer: B
arr+1 points to second element (arr[1]). Dereferencing gives value 20.
Q.29Easy
What will be the size in bytes of int arr[5] on a 32-bit system?
Answer: C
On 32-bit systems, int is typically 4 bytes. 5 elements × 4 bytes = 20 bytes total.
Q.30Easy
Consider the following code:
char str[] = "HELLO";
int len = 0;
while(str[len] != '\0') {
len++;
}
printf("%d", len);
What will be the output?
Answer: A
The string "HELLO" has 5 characters. The while loop counts characters until it encounters the null terminator '\0'. The output will be 5. The null terminator is not counted in the length.