MCQ PORTAL

Back to All Topics

Arrays and Strings

Showing 24 of 24 questions in this topic

Start Practice Mode

Answer Green MarksON

Correct answers are highlighted in green

C042Arrays and Strings • Array index
Most ImportantEasy

Q1.The index of the FIRST element of an array in C is:

A
1
B
0
Correct answer
C
-1
D
depends on compiler
C043Arrays and Strings • Array declaration
Most ImportantEasy

Q2.How many integers can the array int a[5]; store?

A
4
B
5
Correct answer
C
6
D
1
C044Arrays and Strings • Array index
Most ImportantEasy

Q3.For int a[5]; the valid index range is:

A
0 to 5
B
1 to 5
C
0 to 4
Correct answer
D
1 to 4
C045Arrays and Strings • 2D array
Most ImportantEasy

Q4.How do you declare a 2D integer array with 3 rows and 4 columns?

A
int a[3,4];
B
int a[3][4];
Correct answer
C
int a(3)(4);
D
int a[7];
C046Arrays and Strings • String functions
Most ImportantEasy

Q5.Which function returns the length of a string?

A
strlen()
Correct answer
B
strcpy()
C
strcat()
D
strcmp()
C048Arrays and Strings • Null terminator
Most ImportantMedium

Q6.Every string in C is terminated by which character?

A
\n (newline)
B
\0 (null character)
Correct answer
C
\t (tab)
D
a space
C053Arrays and Strings • Memory layout
Most ImportantMedium

Q7.Array elements in C are stored in:

A
random memory locations
B
contiguous (consecutive) memory locations
Correct answer
C
reverse order
D
linked nodes
C130Arrays and Strings • Array size
Most ImportantEasy

Q8.How many elements does int a[] = {1, 2, 3, 4}; have?

A
3
B
4
Correct answer
C
5
D
0
C135Arrays and Strings • 2D array
Most ImportantEasy

Q9.How many elements can int a[2][3]; store?

A
5
B
6
Correct answer
C
23
D
8
C047Arrays and Strings • String header
ImportantEasy

Q10.Which header file is required for string functions like strlen() and strcpy()?

A
<stdio.h>
B
<string.h>
Correct answer
C
<ctype.h>
D
<math.h>
C049Arrays and Strings • strlen
ImportantMedium

Q11.What value does strlen("HELLO") return?

A
4
B
5
Correct answer
C
6
D
1
C050Arrays and Strings • String storage
ImportantMedium

Q12.What is the minimum array size needed to store the string "HELLO"?

A
5
B
6
Correct answer
C
4
D
10
C051Arrays and Strings • strcat
ImportantEasy

Q13.The function strcat() is used to:

A
copy a string
B
compare two strings
C
join (concatenate) two strings
Correct answer
D
find string length
C052Arrays and Strings • strcmp
ImportantMedium

Q14.strcmp(s1, s2) returns 0 when:

A
s1 is greater than s2
B
s1 is smaller than s2
C
both strings are equal
Correct answer
D
always
C131Arrays and Strings • Pointer equivalence
ImportantHard

Q15.For an array a, the expression a[i] is equivalent to:

A
*(a + i)
Correct answer
B
*(a) + i
C
a + i
D
&a[i]
C132Arrays and Strings • Char array
ImportantMedium

Q16.How many elements does char name[] = "RAM"; contain?

A
3
B
4
Correct answer
C
5
D
2
C133Arrays and Strings • String input
ImportantMedium

Q17.scanf("%s", str) stops reading the string when it reaches:

A
a full stop
B
whitespace (space, tab or newline)
Correct answer
C
a comma
D
the letter z
C134Arrays and Strings • String comparison
ImportantMedium

Q18.Which of the following CANNOT be used to compare two strings in C?

A
strcmp()
B
the == operator
Correct answer
C
a loop comparing characters
D
strncmp()
C138Arrays and Strings • 2D index
ImportantEasy

Q19.The top-left element of int a[5][5]; is accessed as:

A
a[1][1]
B
a[0][0]
Correct answer
C
a[5][5]
D
a[0]
C140Arrays and Strings • strcpy
ImportantEasy

Q20.In strcpy(dest, src); the copying happens:

A
from dest into src
B
from src into dest
Correct answer
C
in both directions
D
not at all
C141Arrays and Strings • Array to function
ImportantHard

Q21.When an array is passed to a function, what is actually passed?

A
a copy of every element
B
the base address of the array
Correct answer
C
only the first element
D
the array size
C136Arrays and Strings • 2D array
OtherHard

Q22.In memory, the elements of a 2D array in C are stored in:

A
column-major order
B
row-major order
Correct answer
C
random order
D
reverse order
C137Arrays and Strings • Line input
OtherMedium

Q23.To read a full line of text including spaces, which function is suitable?

A
scanf("%s")
B
getchar()
C
fgets() / gets()
Correct answer
D
strlen()
C139Arrays and Strings • Array size rule
OtherMedium

Q24.In standard C, the size of an ordinary array must be a:

A
float value
B
constant known at compile time
Correct answer
C
string
D
negative number