C Programming — Arrays & Strings
C language from basics to advanced placement prep
100 Questions 10 Topics Take Test
Advertisement
Showing 91–100 of 100 questions in Arrays & Strings
Q.91 Medium Arrays & Strings
What will be printed by: printf("%s", "Hello\0World");?
A HelloWorld
B Hello
C World
D Hello\0World
Correct Answer:  B. Hello
EXPLANATION

\0 is the null terminator which marks the end of a string. %s stops printing at the first null character.

Take Test
Q.92 Medium Arrays & Strings
What is the output of the following code?
int arr[] = {10, 20, 30};
printf("%d", sizeof(arr)/sizeof(arr[0]));
A 1
B 2
C 3
D 6
Correct Answer:  C. 3
EXPLANATION

sizeof(arr) gives total bytes of array. sizeof(arr[0]) gives bytes of one element. Division gives number of elements: 3.

Take Test
Q.93 Medium Arrays & Strings
Which function is used to reverse a string in C library?
A reverse()
B strrev()
C String reversal is not in standard C library
D revstr()
Correct Answer:  C. String reversal is not in standard C library
EXPLANATION

There is no standard library function for string reversal. strrev() is non-standard (available in some compilers). Manual reversal or custom functions are needed.

Take Test
Q.94 Medium Arrays & Strings
What is the difference between char str[] = "Test" and char *str = "Test"?
A No difference
B First is array, second is pointer; first is modifiable, second is read-only
C First is pointer, second is array
D First causes error, second is valid
Correct Answer:  B. First is array, second is pointer; first is modifiable, second is read-only
EXPLANATION

char[] creates a modifiable array with its own storage. char* points to read-only string literal in memory.

Take Test
Q.95 Medium Arrays & Strings
What will be the output of the following code?
char str[] = "Code";
printf("%c", str[2]);
A C
B o
C d
D e
Correct Answer:  C. d
EXPLANATION

String "Code" has indices: C(0), o(1), d(2), e(3). str[2] refers to 'd'.

Take Test
Consider a 2D array declared as: int matrix[3][4]. How many elements does it have?
A 3
B 4
C 7
D 12
Correct Answer:  D. 12
EXPLANATION

A 2D array with dimensions 3x4 has 3*4 = 12 total elements.

Take Test
What does the following code do? strcpy(dest, src);
A Compares two strings
B Copies string src to dest
C Concatenates two strings
D Finds length of string
Correct Answer:  B. Copies string src to dest
EXPLANATION

strcpy() copies the contents of the source string to the destination string.

Take Test
Which of the following is NOT a valid string initialization?
A char str[] = "Program";
B char str[10] = {'P','r','o','g'};
C char str[10]; str = "Program";
D char *str = "Program";
Correct Answer:  C. char str[10]; str = "Program";
EXPLANATION

Array names are constant pointers and cannot be reassigned. Direct assignment to char array after declaration is invalid.

Take Test
What will be the output of strlen("Hello") in C?
A 4
B 5
C 6
D Error
Correct Answer:  B. 5
EXPLANATION

strlen() returns the length of the string excluding the null terminator '\0'. "Hello" has 5 characters.

Take Test
Q.100 Easy Arrays & Strings
What is the correct way to declare a 1D array of 10 integers in C?
A int arr[10];
B int arr(10);
C int arr{10};
D int [10]arr;
Correct Answer:  A. int arr[10];
EXPLANATION

In C, arrays are declared with the syntax: datatype arrayname[size]. Option A follows the correct syntax.

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