Consider: int arr[10]; int *ptr = arr; What does ptr[5] represent?
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));
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?
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?
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);
The array has 5 characters but is not null-terminated. printf("%s") will read beyond the array, printing garbage.
Advertisement
Consider a 3D array: int arr[2][3][4]. How many elements total?
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]?
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?
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?
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:
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?
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]?
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.
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.