What is the output of printf("%d", sizeof(arr)) for char arr[100]?
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?
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?
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?
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?
Array names are non-modifiable lvalues. You cannot use ++ on them. However, individual elements can be accessed and modified.
Advertisement
In a string with escape sequences like "Hello\nWorld", how many characters are counted by strlen()?
\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'?
%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?
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?
String functions expect null terminator. This array has no '\0', so it's a character array but NOT a proper string for str* functions.