What is the correct way to declare a 1D array of 10 integers in C?
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?
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?
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);
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 2D array with dimensions 3x4 has 3*4 = 12 total elements.
Advertisement
If an integer array arr[10] is declared globally in C, what will be the initial values of its elements?
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:
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?
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?
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"?
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));
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?
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?
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];?
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]);
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]);
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]);
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 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?
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?
int occupies 4 bytes. Array size is 3×4 = 12 elements. Total: 12 × 4 = 48 bytes.