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'.
What is the difference between arr[5] and *arr when arr is an array?
A No difference, both access the same element B arr[5] accesses 6th element, *arr accesses 1st element C arr[5] is address, *arr is value D No valid comparison
arr[5] accesses the element at index 5 (6th element), while *arr (equivalent to arr[0]) accesses the first element.
Which statement about 2D arrays in C is correct?
A int arr[3][4] requires 12 contiguous bytes B arr[0] returns the address of the first row C arr[0][0] and *(*arr) access the same element D Both B and C
arr[0] points to the first row (array of 4 ints). arr[0][0] and *(*arr) both access the first element through pointer dereferencing.
What is the output? char str[6] = {'H','e','l','l','o'}; printf("%s", str);
A Hello B Helo C Garbage output D Compilation error
The array has 5 characters but is not null-terminated. printf("%s") will read beyond the array, printing garbage.
Consider a 3D array: int arr[2][3][4]. How many elements total?
A 9 elements B 24 elements C 12 elements D 6 elements
Total elements = 2 × 3 × 4 = 24 elements in the 3D array.
What will be the result of accessing arr[10] when arr is declared as int arr[5]?
A Compilation error B Runtime error C Undefined behavior - may access memory beyond array D Returns 0 by default
C doesn't perform bounds checking. Accessing out-of-bounds memory causes undefined behavior and is a common source of bugs.
What is the difference between char str[20] and char *str in C?
A No difference, both represent strings B First is array allocation, second is pointer declaration requiring separate allocation C First is dynamic, second is static D Second can hold longer strings
char str[20] allocates 20 bytes on stack. char *str only declares a pointer and requires separate memory allocation (malloc/static string).
What does strcpy(dest, src) do, and what is its main risk?
A Copies src to dest; risk is slow performance B Copies src to dest; risk is buffer overflow if dest is too small C Creates a new string; risk is memory leak D Compares two strings; no risk
strcpy() doesn't check destination buffer size, potentially causing buffer overflow. Modern alternatives include strncpy() or strcpy_s().
In a string comparison, strcmp('Apple', 'apple') returns:
A 0 (equal) B A non-zero negative value C A non-zero positive value D Compilation error
strcmp() is case-sensitive. ASCII value of 'A' (65) is less than 'a' (97), so it returns negative value. But 'A' < 'a', so it returns -32 (negative).
What is the memory layout of a 2D array int arr[3][4] in C?
A Random arrangement in memory B Row-major order - sequential rows stored consecutively C Column-major order - sequential columns stored consecutively D Scattered across memory with pointers
C uses row-major order. The entire array is contiguous in memory with all of row 0, then row 1, then row 2, etc.
What is the output of printf("%d", sizeof(arr)) for char arr[100]?
A 100 B 1 C 4 or 8 (depending on pointer size) D 101 (including null terminator)
sizeof(arr) returns the total size of the array in bytes. For char arr[100], it returns 100 bytes regardless of content.
Which function is safe to use for string concatenation with size limiting?
A strcat() B strncat() C concat() D appendstr()
strncat() allows specifying maximum characters to concatenate, preventing buffer overflow. strcat() has no size limit.
In C, what happens when you pass an array to a function?
A The entire array is copied to function stack B Only the array name (pointer to first element) is passed C A deep copy is created D The array is passed by reference automatically
Arrays decay to pointers when passed to functions. Only the address of the first element is passed, not a copy of entire array.
What does the expression *(arr + 3) represent for an integer array?
A Address of 4th element B Value of 4th element (0-indexed as arr[3]) C Size of array plus 3 D Third pointer in array
arr + 3 points to the 4th element (0-indexed). Dereferencing with * gives its value, equivalent to arr[3].
Which of the following operations is NOT allowed on array names in C?
A arr[0] (indexing) B arr++ (incrementing) C sizeof(arr) (size calculation) D &arr (address of)
Array names are non-modifiable lvalues. You cannot use ++ on them. However, individual elements can be accessed and modified.
In a string with escape sequences like "Hello\nWorld", how many characters are counted by strlen()?
A 10 B 11 C 12 D 13
\n is a single character (newline). 'Hello' = 5 + \n = 1 + 'World' = 5, total = 11 characters (not counting null terminator).
What is the output of: char str[20]; scanf("%s", str); when input is 'Hello World'?
A Entire 'Hello World' is stored B Only 'Hello' is stored (stops at whitespace) C Compilation error D Buffer overflow occurs
%s format specifier stops reading at whitespace. To read entire line including spaces, use fgets() or %[^\n].
What is the correct syntax to pass a 2D array to a function?
A void func(int arr[][]) B void func(int arr[3][4]) C void func(int **arr) D Any of the above
First dimension can be omitted, but second must be specified: int arr[][4]. Option C (int **arr) is not equivalent - it's pointer to pointer.
For char arr[5] = {'a', 'b', 'c', 'd', 'e'}, is this a valid string?
A Yes, always valid B No, missing null terminator C Only if last element is '\0' D Depends on compiler
String functions expect null terminator. This array has no '\0', so it's a character array but NOT a proper string for str* functions.