Govt. Exams
Entrance Exams
strspn(str, charset) returns length of initial segment of str containing only characters from charset. Useful for token parsing.
strcpy() assumes null-terminated strings. memcpy() copies exact number of bytes, suitable for binary data or embedded nulls.
Parentheses change precedence. int (*ptr)[5] is pointer to array of 5 ints. int *arr[5] is array of 5 pointers.
gets() has no buffer overflow protection and was removed in C11. fgets(str, size, stdin) is the safer alternative with size limiting.
In row-major order: address = base + (i*m*n + j*n + k) where m=3, n=4. So arr[1][2][3] = base + 1*12 + 2*4 + 3 = base + 23.
String literals are stored in read-only memory. Attempting to modify them causes undefined behavior or segmentation fault at runtime.
C standard defines arr[i] as *(arr + i). Both notations access the same memory location and perform identically.
memcpy() is the most efficient as it performs block memory copy. strcpy() is only for strings, and array assignment doesn't work in C.
For dynamic allocation, use double pointer char** and allocate memory for each string separately. Options B and C are static allocations.
int arr[3] = {10, 20, 30};
int *p = arr;
printf("%d %d", *p++, *++p);
This code exhibits undefined behavior due to lack of sequence points between modifications and access of p. Different compilers may produce different results.