C Programming — Arrays & Strings
C language from basics to advanced placement prep
49 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 49 questions in Arrays & Strings
Q.1 Medium Arrays & Strings
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
Correct Answer:  B. No, missing null terminator
EXPLANATION

String functions expect null terminator. This array has no '\0', so it's a character array but NOT a proper string for str* functions.

Take Test
Q.2 Medium Arrays & Strings
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
Correct Answer:  B. void func(int arr[3][4])
EXPLANATION

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.

Take Test
Q.3 Medium Arrays & Strings
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
Correct Answer:  B. Only 'Hello' is stored (stops at whitespace)
EXPLANATION

%s format specifier stops reading at whitespace. To read entire line including spaces, use fgets() or %[^\n].

Take Test
Q.4 Medium Arrays & Strings
In a string with escape sequences like "Hello\nWorld", how many characters are counted by strlen()?
A 10
B 11
C 12
D 13
Correct Answer:  B. 11
EXPLANATION

\n is a single character (newline). 'Hello' = 5 + \n = 1 + 'World' = 5, total = 11 characters (not counting null terminator).

Take Test
Q.5 Medium Arrays & Strings
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)
Correct Answer:  B. arr++ (incrementing)
EXPLANATION

Array names are non-modifiable lvalues. You cannot use ++ on them. However, individual elements can be accessed and modified.

Take Test
Advertisement
Q.6 Medium Arrays & Strings
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
Correct Answer:  B. Value of 4th element (0-indexed as arr[3])
EXPLANATION

arr + 3 points to the 4th element (0-indexed). Dereferencing with * gives its value, equivalent to arr[3].

Take Test
Q.7 Medium Arrays & Strings
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
Correct Answer:  B. Only the array name (pointer to first element) is passed
EXPLANATION

Arrays decay to pointers when passed to functions. Only the address of the first element is passed, not a copy of entire array.

Take Test
Q.8 Medium Arrays & Strings
Which function is safe to use for string concatenation with size limiting?
A strcat()
B strncat()
C concat()
D appendstr()
Correct Answer:  B. strncat()
EXPLANATION

strncat() allows specifying maximum characters to concatenate, preventing buffer overflow. strcat() has no size limit.

Take Test
Q.9 Medium Arrays & Strings
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)
Correct Answer:  A. 100
EXPLANATION

sizeof(arr) returns the total size of the array in bytes. For char arr[100], it returns 100 bytes regardless of content.

Take Test
Q.10 Medium Arrays & Strings
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
Correct Answer:  B. Row-major order - sequential rows stored consecutively
EXPLANATION

C uses row-major order. The entire array is contiguous in memory with all of row 0, then row 1, then row 2, etc.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips