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.