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.62Medium
What is the difference between arr[5] and *arr when arr is an array?
Answer: B
arr[5] accesses the element at index 5 (6th element), while *arr (equivalent to arr[0]) accesses the first element.
Q.63Medium
Which statement about 2D arrays in C is correct?
Answer: D
arr[0] points to the first row (array of 4 ints). arr[0][0] and *(*arr) both access the first element through pointer dereferencing.
Q.64Medium
What is the output?
char str[6] = {'H','e','l','l','o'};
printf("%s", str);
Answer: C
The array has 5 characters but is not null-terminated. printf("%s") will read beyond the array, printing garbage.
Q.65Medium
Consider a 3D array: int arr[2][3][4]. How many elements total?
Answer: B
Total elements = 2 × 3 × 4 = 24 elements in the 3D array.
Advertisement
Q.66Hard
What happens with this code?
char *ptr;
char str[] = "Programming";
ptr = str;
ptr[2] = 'X';
Answer: B
ptr points to the character array str. Modifying ptr[2] modifies str[2], changing 'o' to 'X', resulting in 'PrXgramming'.
Q.67Hard
What will the following code print?
int arr[3] = {10, 20, 30};
int *p = arr;
printf("%d %d", *p++, *++p);
Answer: D
This code exhibits undefined behavior due to lack of sequence points between modifications and access of p. Different compilers may produce different results.
Q.68Hard
How should dynamic 1D array of strings be declared for 5 strings of length 20?
Answer: A
For dynamic allocation, use double pointer char** and allocate memory for each string separately. Options B and C are static allocations.
Q.69Hard
What is the most efficient way to copy one array to another in C?
Answer: A
memcpy() is the most efficient as it performs block memory copy. strcpy() is only for strings, and array assignment doesn't work in C.
Q.70Easy
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.71Easy
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.72Easy
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.73Easy
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.
Q.74Medium
What will be the result of accessing arr[10] when arr is declared as int arr[5]?
Answer: C
C doesn't perform bounds checking. Accessing out-of-bounds memory causes undefined behavior and is a common source of bugs.
Q.75Medium
What is the difference between char str[20] and char *str in C?
Answer: B
char str[20] allocates 20 bytes on stack. char *str only declares a pointer and requires separate memory allocation (malloc/static string).
Q.76Easy
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.77Medium
What does strcpy(dest, src) do, and what is its main risk?
Answer: B
strcpy() doesn't check destination buffer size, potentially causing buffer overflow. Modern alternatives include strncpy() or strcpy_s().
Q.78Medium
In a string comparison, strcmp('Apple', 'apple') returns:
Answer: C
strcmp() is case-sensitive. ASCII value of 'A' (65) is less than 'a' (97), so it returns negative value. But 'A' < 'a', so it returns -32 (negative).
Q.79Medium
What is the memory layout of a 2D array int arr[3][4] in C?
Answer: B
C uses row-major order. The entire array is contiguous in memory with all of row 0, then row 1, then row 2, etc.
Q.80Medium
What is the output of printf("%d", sizeof(arr)) for char arr[100]?
Answer: A
sizeof(arr) returns the total size of the array in bytes. For char arr[100], it returns 100 bytes regardless of content.