Entrance Exams
Govt. Exams
ptr[5] is equivalent to *(ptr+5), which accesses the 5th element. Pointer arithmetic adjusts by the size of int.
char str[] = "GATE";
printf("%d", sizeof(str));
sizeof(str) returns 5 because the array includes 4 characters plus 1 null terminator.
strrev() is a non-standard but commonly used function (available in string.h in some compilers) that reverses a string in-place.
char *str = "Hello";
str[0] = 'J';
String literals are stored in read-only memory. Attempting to modify them causes undefined behavior or segmentation fault.
char (*ptr)[] declares ptr as a pointer to a character array. The parentheses are crucial for correct precedence.
strtok() returns a pointer to the next token separated by the delimiter. Returns NULL when no more tokens exist.
strcpy copies "Hello" and adds null terminator at position 5. Positions 6-9 remain uninitialized.
char str[] = "HELLO";
for(int i = 0; str[i]; i++) str[i] = str[i] + 32;
Adding 32 to uppercase ASCII values converts them to lowercase (A=65, a=97, difference=32).
strcat() is unsafe due to buffer overflow risk. strncat() and sprintf() provide bounds checking.
A compares pointers, not string content. strcmp() compares actual string values character by character.