Govt Exams
char *str = "Hello";
printf("%c", str[1]);
str[1] accesses the second character of the string, which is 'e'.
10 rows × 20 columns × 4 bytes per int = 800 bytes (assuming 4-byte integer).
strlen() returns the length of the string excluding the null terminator. "Hello" has 5 characters.
Both are valid ways to declare arrays of strings. Option A creates a 2D array, Option B creates an array of pointers to strings.
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.
strlen() counts characters before the null terminator. "C2025" has 5 characters, so strlen returns 5. The null terminator is not counted.
Array access by index is O(1) because arrays use contiguous memory allocation, allowing direct access via base address + offset calculation.
char name[50] allocates exactly 50 bytes. The null terminator '\0' must fit within this 50-byte allocation.
In C, strings are null-terminated character arrays. The null character '\0' marks the end of the string.
Global arrays in C are automatically initialized to 0 by default. Only local arrays contain garbage values.