Govt Exams
strchr() finds the first occurrence of a character. strrchr() finds the last occurrence. strstr() finds substrings.
10 rows × 20 columns × 4 bytes per int = 800 bytes (assuming 4-byte integer).
strlen() returns the length of the string excluding the null terminator. "Hello" has 5 characters.
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.
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.
int *arr[10] declares an array of 10 pointers to int (subscript binds tighter than dereference). Use int (*arr)[10] for pointer to array.
strncpy with buffer size check and explicit null termination is the standard safe approach. Option A lacks bounds checking; C and D have issues with null termination.
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.
ptr[3] is equivalent to arr[3] and accesses the element at address *(ptr+3). For int*, ptr+3 moves 12 bytes (3×4 bytes) in memory.