Entrance Exams
Govt. Exams
\0 is the null terminator which marks the end of a string. %s stops printing at the first null character.
int arr[] = {10, 20, 30};
printf("%d", sizeof(arr)/sizeof(arr[0]));
sizeof(arr) gives total bytes of array. sizeof(arr[0]) gives bytes of one element. Division gives number of elements: 3.
There is no standard library function for string reversal. strrev() is non-standard (available in some compilers). Manual reversal or custom functions are needed.
char[] creates a modifiable array with its own storage. char* points to read-only string literal in memory.
char str[] = "Code";
printf("%c", str[2]);
String "Code" has indices: C(0), o(1), d(2), e(3). str[2] refers to 'd'.
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.
strlen() returns the length of the string excluding the null terminator '\0'. "Hello" has 5 characters.
In C, arrays are declared with the syntax: datatype arrayname[size]. Option A follows the correct syntax.