Home Subjects C Programming Arrays & Strings

C Programming
Arrays & Strings

C language from basics to advanced placement prep

30 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–20 of 30
Topics in C Programming
How many bytes does a 2D array int arr[3][4] occupy in memory?
A 12 bytes
B 24 bytes
C 48 bytes
D 16 bytes
Correct Answer:  C. 48 bytes
EXPLANATION

int occupies 4 bytes. Array size is 3×4 = 12 elements. Total: 12 × 4 = 48 bytes.

Test
Which function is used to find the length of a string in C?
A strlen()
B strsize()
C stringlen()
D getlength()
Correct Answer:  A. strlen()
EXPLANATION

strlen() is the standard library function defined in string.h that returns the length of a string excluding the null terminator.

Test
What is the maximum size of a string that can be stored in char str[50]?
A 49 characters plus null terminator
B 50 characters plus null terminator
C 50 characters without null terminator
D Unlimited characters
Correct Answer:  A. 49 characters plus null terminator
EXPLANATION

A char array of size 50 can store maximum 49 characters because the last position is reserved for the null terminator '\0'.

Test
What is the output?
int arr[] = {10, 20, 30, 40};
int *p = arr;
printf("%d", p[2]);
A 10
B 20
C 30
D 40
Correct Answer:  C. 30
EXPLANATION

p points to arr[0]. p[2] is equivalent to *(p+2), which points to arr[2] = 30.

Test
Predict the output:
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
printf("%d", arr[1][2]);
A 5
B 6
C 8
D 9
Correct Answer:  B. 6
EXPLANATION

arr[1][2] refers to row 1, column 2, which contains 6.

Test
What will be printed?
char *str = "Hello";
printf("%c", str[1]);
A H
B e
C l
D Compilation error
Correct Answer:  B. e
EXPLANATION

str[1] accesses the second character of the string, which is 'e'.

Test
How many bytes are allocated by: int arr[10][20];?
A 200 bytes
B 400 bytes
C 800 bytes
D 2000 bytes
Correct Answer:  C. 800 bytes
EXPLANATION

10 rows × 20 columns × 4 bytes per int = 800 bytes (assuming 4-byte integer).

Test
What is the output of strlen("Hello") in C?
A 5
B 6
C 4
D Runtime error
Correct Answer:  A. 5
EXPLANATION

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

Test
Which of the following correctly declares a 2D array of strings?
A char str[5][20];
B char *str[5];
C Both A and B are valid
D char str[5, 20];
Correct Answer:  C. Both A and B are valid
EXPLANATION

Both are valid ways to declare arrays of strings. Option A creates a 2D array, Option B creates an array of pointers to strings.

Test
What will be the output of the following code?
int arr[] = {1, 2, 3, 4, 5};
printf("%d", *(arr + 3));
A 4
B 3
C 5
D Compilation error
Correct Answer:  A. 4
EXPLANATION

arr + 3 points to the 4th element (index 3) which is 4. Dereferencing gives 4.

Test
IGET
IGET AI
Online · Exam prep assistant
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