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 is the correct way to declare and initialize a string in C?
A char str = "Hello"; B char *str = "Hello"; OR char str[] = "Hello"; C String str = "Hello"; D char str[10] = {"Hello"};
Option B shows two valid ways: pointer to string literal or character array. Option A is wrong (single char), C is wrong (no String type in C).
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 relationship between pointer arithmetic and array indexing in C?
A Pointer arithmetic is faster than array indexing B arr[i] is equivalent to *(arr + i) - both are mathematically identical C Array indexing is only for static arrays, pointer arithmetic for dynamic D No relationship - they are completely different operations
C standard defines arr[i] as *(arr + i). Both notations access the same memory location and perform identically.
What potential issue exists with this code: char *ptr = "Hello"; ptr[0] = 'h';?
A Compilation error B Attempting to modify a string literal (undefined behavior) C Memory leak D Syntax error in character assignment
String literals are stored in read-only memory. Attempting to modify them causes undefined behavior or segmentation fault at runtime.
For a 3D array int arr[2][3][4], what is arr[1][2][3] equivalent to?
A arr + 2*3*4 + 2*4 + 3 B arr + 1*3*4 + 2*4 + 3 C arr + 3 + 2 + 1 D arr + 1 + 2 + 3
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.
What is the output of: int arr[] = {10, 20, 30}; printf("%d", *(arr+1));?
A 10 B 20 C 30 D Garbage value
arr+1 points to second element (arr[1]). Dereferencing gives value 20.
In string handling, what is the difference between fgets() and gets()?
A fgets() is slower B fgets() includes newline character, gets() doesn't C fgets() takes size parameter and is safer; gets() is unsafe (removed from C11) D gets() works only with integers
gets() has no buffer overflow protection and was removed in C11. fgets(str, size, stdin) is the safer alternative with size limiting.
What will be the size in bytes of int arr[5] on a 32-bit system?
A 5 bytes B 10 bytes C 20 bytes D Depends on compiler
On 32-bit systems, int is typically 4 bytes. 5 elements × 4 bytes = 20 bytes total.
Which of the following correctly declares a pointer to an array (not array of pointers)?
A int *arr[5]; B int (*ptr)[5]; C int [5]*ptr; D int &arr[5];
Parentheses change precedence. int (*ptr)[5] is pointer to array of 5 ints. int *arr[5] is array of 5 pointers.
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].
In what scenario would you use memcpy() instead of strcpy()?
A memcpy() is always faster B When copying binary data or strings without null terminators C When the destination is smaller D memcpy() is safer
strcpy() assumes null-terminated strings. memcpy() copies exact number of bytes, suitable for binary data or embedded nulls.
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.
What does the strspn() function do?
A Finds substring in a string B Spans the initial segment containing only characters from specified set C Compares two strings D Reverses a string
strspn(str, charset) returns length of initial segment of str containing only characters from charset. Useful for token parsing.
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.