Consider: int arr[10]; int *ptr = arr; What does ptr[5] represent?
Answer: D
ptr[5] is equivalent to *(ptr+5), which accesses the 5th element. Pointer arithmetic adjusts by the size of int.
Q.442Medium
What will be printed?
char str[] = "Hello";
printf("%c", *(str+2));
Answer: C
str+2 points to the 3rd character (index 2). *(str+2) dereferences it, printing 'l'.
Q.443Easy
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.444Medium
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.445Medium
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.
Advertisement
Q.446Medium
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.447Medium
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.
Q.448Hard
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.449Hard
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.450Hard
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.451Hard
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.452Easy
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.453Easy
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.454Easy
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.455Easy
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.456Medium
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.457Medium
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.458Easy
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.459Medium
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.460Medium
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).