What is the correct way to declare a 1D array of 10 integers in C?
A int arr[10]; B int arr(10); C int arr{10}; D int [10]arr;
In C, arrays are declared with the syntax: datatype arrayname[size]. Option A follows the correct syntax.
What will be the output of strlen("Hello") in C?
A 4 B 5 C 6 D Error
strlen() returns the length of the string excluding the null terminator '\0'. "Hello" has 5 characters.
Which of the following is NOT a valid string initialization?
A char str[] = "Program"; B char str[10] = {'P','r','o','g'}; C char str[10]; str = "Program"; D char *str = "Program";
Array names are constant pointers and cannot be reassigned. Direct assignment to char array after declaration is invalid.
What does the following code do? strcpy(dest, src);
A Compares two strings B Copies string src to dest C Concatenates two strings D Finds length of string
strcpy() copies the contents of the source string to the destination string.
Consider a 2D array declared as: int matrix[3][4]. How many elements does it have?
A 3 B 4 C 7 D 12
A 2D array with dimensions 3x4 has 3*4 = 12 total elements.
If an integer array arr[10] is declared globally in C, what will be the initial values of its elements?
A All elements initialized to 0 B All elements contain garbage values C All elements initialized to 1 D Elements are uninitialized until explicitly set
Global arrays in C are automatically initialized to 0 by default. Only local arrays contain garbage values.
In C, a string is internally represented as:
A An array of characters terminated by '\0' B An array of integers with length prefix C A special data type with built-in length D A pointer to the first character with separate length variable
In C, strings are null-terminated character arrays. The null character '\0' marks the end of the string.
How much memory is allocated for char name[50] declaration?
A 50 bytes B 49 bytes C 51 bytes D Depends on compiler
char name[50] allocates exactly 50 bytes. The null terminator '\0' must fit within this 50-byte allocation.
What is the time complexity of accessing an element at index 5 in an array?
A O(1) - Constant time B O(n) - Linear time C O(log n) - Logarithmic time D O(n²) - Quadratic time
Array access by index is O(1) because arrays use contiguous memory allocation, allowing direct access via base address + offset calculation.
What does strlen() function return for the string "C2025"?
A 5 B 6 C 4 D Undefined behavior
strlen() counts characters before the null terminator. "C2025" has 5 characters, so strlen returns 5. The null terminator is not counted.
What will be the output of the following code? int arr[] = {1, 2, 3, 4, 5}; printf("%d", *(arr + 3));
A 4 B 3 C 5 D Compilation error
arr + 3 points to the 4th element (index 3) which is 4. Dereferencing gives 4.
Which of the following correctly declares a 2D array of strings?
A char str[5][20]; B char *str[5]; C Both A and B are valid D char str[5, 20];
Both are valid ways to declare arrays of strings. Option A creates a 2D array, Option B creates an array of pointers to strings.
What is the output of strlen("Hello") in C?
A 5 B 6 C 4 D Runtime error
strlen() returns the length of the string excluding the null terminator. "Hello" has 5 characters.
How many bytes are allocated by: int arr[10][20];?
A 200 bytes B 400 bytes C 800 bytes D 2000 bytes
10 rows × 20 columns × 4 bytes per int = 800 bytes (assuming 4-byte integer).
What will be printed? char *str = "Hello"; printf("%c", str[1]);
A H B e C l D Compilation error
str[1] accesses the second character of the string, which is 'e'.
Predict the output: int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; printf("%d", arr[1][2]);
A 5 B 6 C 8 D 9
arr[1][2] refers to row 1, column 2, which contains 6.
What is the output? int arr[] = {10, 20, 30, 40}; int *p = arr; printf("%d", p[2]);
A 10 B 20 C 30 D 40
p points to arr[0]. p[2] is equivalent to *(p+2), which points to arr[2] = 30.
What is the maximum size of a string that can be stored in char str[50]?
A 49 characters plus null terminator B 50 characters plus null terminator C 50 characters without null terminator D Unlimited characters
A char array of size 50 can store maximum 49 characters because the last position is reserved for the null terminator '\0'.
Which function is used to find the length of a string in C?
A strlen() B strsize() C stringlen() D getlength()
strlen() is the standard library function defined in string.h that returns the length of a string excluding the null terminator.
How many bytes does a 2D array int arr[3][4] occupy in memory?
A 12 bytes B 24 bytes C 48 bytes D 16 bytes
int occupies 4 bytes. Array size is 3×4 = 12 elements. Total: 12 × 4 = 48 bytes.