Govt. Exams
Entrance Exams
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.
A 2D array with dimensions 3x4 has 3*4 = 12 total elements.
strcpy() copies the contents of the source string to the destination string.
Array names are constant pointers and cannot be reassigned. Direct assignment to char array after declaration is invalid.