Entrance Exams
Govt. Exams
p points to arr[0]. p+2 points to arr[2], which contains 30.
char arr[] = "ABC";
printf("%d", sizeof(arr));
sizeof includes the null terminator. "ABC" has 4 bytes (A, B, C, \0).
strchr() finds the first occurrence of a character. strrchr() finds the last occurrence. strstr() finds substrings.
Inserting at the beginning requires shifting all n elements one position right, making it O(n). Insertion at the end is O(1) if space exists.
String literals are stored in read-only memory. Attempting modification causes undefined behavior (often segmentation fault). This is why char *str = "text"; str[0]='T'; is dangerous.
Both strtok() (modifies by replacing delimiters with '\0') and strcpy() (copies and overwrites destination) modify strings in-place.
This expression calculates array length. sizeof(arr) gives total bytes (40 on 32-bit system), sizeof(arr[0]) gives bytes per element (4), so 40/4=10.
C uses row-major order for 2D arrays. matrix[0][0], matrix[0][1]...matrix[0][4], matrix[1][0]... are stored sequentially in memory.
"Hello" has 5 characters, so valid indices are 0-4. Index 5 contains the null terminator '\0' that marks the end of the string.
Array names decay to pointers to the first element in expressions, but they are not truly pointer variables. The array name cannot be reassigned.