Consider the code: int *p; int arr[5] = {10, 20, 30, 40, 50}; p = arr; What is *(p+2)?
A 20 B 30 C 40 D 50
p points to arr[0]. p+2 points to arr[2], which contains 30.
What will be printed? char *str = "Hello"; printf("%c", str[1]);
A H B e C l D Compilation error
str[1] accesses the second character of the string, which is 'e'.
Which of the following will correctly compare two strings?
A if (str1 == str2) B if (strcmp(str1, str2) == 0) C Both A and B D Neither A nor B
A compares pointers, not string content. strcmp() compares actual string values character by character.
What is the correct syntax to concatenate two strings safely in modern C?
A strcat(dest, src) B strncat(dest, src, n) C sprintf(dest, "%s%s", dest, src) D Both B and C are safer options
strcat() is unsafe due to buffer overflow risk. strncat() and sprintf() provide bounds checking.
Predict the output: int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; printf("%d", arr[1][2]);
A 5 B 6 C 8 D 9
arr[1][2] refers to row 1, column 2, which contains 6.
What does the following code do? char str[] = "HELLO"; for(int i = 0; str[i]; i++) str[i] = str[i] + 32;
A Converts uppercase to lowercase B Converts lowercase to uppercase C Shifts ASCII values by 32 D Causes compilation error
Adding 32 to uppercase ASCII values converts them to lowercase (A=65, a=97, difference=32).
In a dynamic 2D array created as: int arr = (int )malloc(rows * sizeof(int*)); What is the next step?
A Directly assign values to arr[i][j] B Allocate memory for each row C Call free() immediately D Use strdup() to copy strings
After allocating the array of pointers, each row must be allocated separately.
What will happen? char arr[5] = "Hello"; printf("%d", strlen(arr));
A 5 B 6 C Compilation error D Undefined behavior
Array is too small. "Hello" needs 6 bytes including null terminator, but only 5 are allocated. This causes buffer overflow.
Consider: char str[10]; strcpy(str, "Hello"); What is the state of memory after this?
A str[5] contains '\0', str[6] is uninitialized B All elements from str[0] to str[9] contain characters C str[0] to str[4] have 'H','e','l','l','o', str[5] has '\0' D Runtime error occurs
strcpy copies "Hello" and adds null terminator at position 5. Positions 6-9 remain uninitialized.
What is the output? int arr[] = {10, 20, 30, 40}; int *p = arr; printf("%d", p[2]);
A 10 B 20 C 30 D 40
p points to arr[0]. p[2] is equivalent to *(p+2), which points to arr[2] = 30.
What does strtok(str, delim) return on each call until the string ends?
A The entire remaining string B A pointer to the next token C The delimiter character D The length of the token
strtok() returns a pointer to the next token separated by the delimiter. Returns NULL when no more tokens exist.
What is the maximum size of a string that can be stored in char str[50]?
A 49 characters plus null terminator B 50 characters plus null terminator C 50 characters without null terminator D Unlimited characters
A char array of size 50 can store maximum 49 characters because the last position is reserved for the null terminator '\0'.
Which function is used to find the length of a string in C?
A strlen() B strsize() C stringlen() D getlength()
strlen() is the standard library function defined in string.h that returns the length of a string excluding the null terminator.
How many bytes does a 2D array int arr[3][4] occupy in memory?
A 12 bytes B 24 bytes C 48 bytes D 16 bytes
int occupies 4 bytes. Array size is 3×4 = 12 elements. Total: 12 × 4 = 48 bytes.
What is the correct way to declare a pointer to a character array?
A char *ptr[]; B char (*ptr)[]; C *char ptr[]; D char **ptr;
char (*ptr)[] declares ptr as a pointer to a character array. The parentheses are crucial for correct precedence.
What happens when you try to modify a string literal in C? char *str = "Hello"; str[0] = 'J';
A String is successfully modified to 'Jello' B Undefined behavior or runtime error C Compilation error D String remains 'Hello'
String literals are stored in read-only memory. Attempting to modify them causes undefined behavior or segmentation fault.
Which of the following correctly reverses a string in-place?
A strrev(str); B reverse(str); C str_reverse(str); D reversestr(str);
strrev() is a non-standard but commonly used function (available in string.h in some compilers) that reverses a string in-place.
What is the output of the following code? char str[] = "GATE"; printf("%d", sizeof(str));
A 4 B 5 C 8 D Compilation error
sizeof(str) returns 5 because the array includes 4 characters plus 1 null terminator.
Consider: int arr[10]; int *ptr = arr; What does ptr[5] represent?
A The 5th element of array arr B Address of the 5th element C Value at address arr + 5*sizeof(int) D Both A and C
ptr[5] is equivalent to *(ptr+5), which accesses the 5th element. Pointer arithmetic adjusts by the size of int.
What will be printed? char str[] = "Hello"; printf("%c", *(str+2));
A H B e C l D Compilation error
str+2 points to the 3rd character (index 2). *(str+2) dereferences it, printing 'l'.