Practice 20 Arrays & Strings multiple-choice questions designed for CDAC CCAT exam preparation. Click "Show Answer" to reveal the correct option with detailed explanation.
Show Answer & Explanation
Correct Answer: B — Collection of same data types
An array stores multiple elements of the same data type in contiguous memory locations.
Show Answer & Explanation
Correct Answer: C — Contiguously
Array elements occupy consecutive memory locations, which allows index-based access.
What will be the output?
int a[5] = {1,2,3};
printf("%d", a[3]);Show Answer & Explanation
Correct Answer: A — 0
Uninitialized elements in a partially initialized array are set to 0.
Show Answer & Explanation
Correct Answer: B — 0
In C, array indexing starts from 0.
Show Answer & Explanation
Correct Answer: C — \0
Strings in C are null-terminated, meaning they end with the null character \0.
What will be the output?
`int arr[3] = {10, 20, 30};`
`printf("%d", *(arr + 1));`Show Answer & Explanation
Correct Answer: B — 20
*(arr + 1) is equivalent to arr[1], which is 20. Adding 1 to the array pointer moves to the next element.
Show Answer & Explanation
Correct Answer: B — int arr[3][4];
A 2D array is declared as data_type name[rows][columns]. So int arr[3][4] creates 3 rows and 4 columns.
Show Answer & Explanation
Correct Answer: B — 5
strlen() returns the length of the string excluding the null terminator. "Hello" has 5 characters.
What is the output?
`char str[] = "Hello";`
`printf("%lu", sizeof(str));`Show Answer & Explanation
Correct Answer: B — 6
sizeof() includes the null terminator, so "Hello" occupies 6 bytes (5 characters + 1 null character).
Show Answer & Explanation
Correct Answer: A — strcpy()
strcpy(dest, src) copies the source string to the destination string.
What will be the output?
`int arr[] = {1, 2, 3, 4, 5};`
`printf("%d", arr[5]);`Show Answer & Explanation
Correct Answer: C — Garbage value
arr[5] is out of bounds (valid indices are 0-4). Accessing it results in undefined behavior, typically a garbage value.
Show Answer & Explanation
Correct Answer: C — Concatenates two strings
strcat(dest, src) appends the source string at the end of the destination string.
What is the output?
`char *str = "World";`
`printf("%c", str[0]);`Show Answer & Explanation
Correct Answer: A — W
str[0] accesses the first character of the string, which is "W".
Show Answer & Explanation
Correct Answer: C — Negative value
strcmp() returns negative if first string is less than second. "abc" < "abd" because 'c' < 'd'.
Show Answer & Explanation
Correct Answer: C — By passing the array name
When you pass the array name, you pass the base address (pointer to first element). Arrays decay to pointers when passed to functions.
What is the output?
`char str1[10] = "Hello";`
`char str2[10] = "Hello";`
`printf("%d", str1 == str2);`Show Answer & Explanation
Correct Answer: B — 0
str1 and str2 are different arrays at different memory locations. Comparing them compares addresses, not content, so result is 0 (false).
Show Answer & Explanation
Correct Answer: C — 60
Total elements = 5 × 4 × 3 = 60. A 3D array with dimensions [5][4][3] can store 60 integers.
What is the output?
`char str[] = "Hello\0World";`
`printf("%s", str);`Show Answer & Explanation
Correct Answer: A — Hello
printf with %s stops printing at the first null character (\0). So only "Hello" is printed.
Show Answer & Explanation
Correct Answer: C — <string.h>
String manipulation functions are declared in <string.h> header file.
What will be the output?
`int arr[5] = {0};`
`printf("%d %d", arr[0], arr[4]);`Show Answer & Explanation
Correct Answer: A — 0 0
When an array is initialized with {0}, all elements are set to 0. So both arr[0] and arr[4] are 0.