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.
int occupies 4 bytes. Array size is 3×4 = 12 elements. Total: 12 × 4 = 48 bytes.
strlen() is the standard library function defined in string.h that returns the length of a string excluding the null terminator.
A char array of size 50 can store maximum 49 characters because the last position is reserved for the null terminator '\0'.
strtok() returns a pointer to the next token separated by the delimiter. Returns NULL when no more tokens exist.
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.