Govt Exams
strcpy copies "Hello" and adds null terminator at position 5. Positions 6-9 remain uninitialized.
char arr[5] = "Hello";
printf("%d", strlen(arr));
Array is too small. "Hello" needs 6 bytes including null terminator, but only 5 are allocated. This causes buffer overflow.
After allocating the array of pointers, each row must be allocated separately.
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).
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
printf("%d", arr[1][2]);
arr[1][2] refers to row 1, column 2, which contains 6.
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.
char *str = "Hello";
printf("%c", str[1]);
str[1] accesses the second character of the string, which is 'e'.
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).