Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

291 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 161–170 of 291
Topics in C Programming
Q.161 Easy Arrays & Strings
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
Q.162 Easy Arrays & Strings
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
Q.163 Easy Arrays & Strings
What does strlen() function return for the string "C2025"?
A 5
B 6
C 4
D Undefined behavior
Correct Answer:  A. 5
EXPLANATION

strlen() counts characters before the null terminator. "C2025" has 5 characters, so strlen returns 5. The null terminator is not counted.

Test
Q.164 Easy Arrays & Strings
What is the time complexity of accessing an element at index 5 in an array?
A O(1) - Constant time
B O(n) - Linear time
C O(log n) - Logarithmic time
D O(n²) - Quadratic time
Correct Answer:  A. O(1) - Constant time
EXPLANATION

Array access by index is O(1) because arrays use contiguous memory allocation, allowing direct access via base address + offset calculation.

Test
Q.165 Easy Arrays & Strings
How much memory is allocated for char name[50] declaration?
A 50 bytes
B 49 bytes
C 51 bytes
D Depends on compiler
Correct Answer:  A. 50 bytes
EXPLANATION

char name[50] allocates exactly 50 bytes. The null terminator '\0' must fit within this 50-byte allocation.

Test
Q.166 Easy Arrays & Strings
In C, a string is internally represented as:
A An array of characters terminated by '\0'
B An array of integers with length prefix
C A special data type with built-in length
D A pointer to the first character with separate length variable
Correct Answer:  A. An array of characters terminated by '\0'
EXPLANATION

In C, strings are null-terminated character arrays. The null character '\0' marks the end of the string.

Test
Q.167 Easy Arrays & Strings
If an integer array arr[10] is declared globally in C, what will be the initial values of its elements?
A All elements initialized to 0
B All elements contain garbage values
C All elements initialized to 1
D Elements are uninitialized until explicitly set
Correct Answer:  A. All elements initialized to 0
EXPLANATION

Global arrays in C are automatically initialized to 0 by default. Only local arrays contain garbage values.

Test
Q.168 Easy Arrays & Strings
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.

Test
Q.169 Easy Arrays & Strings
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.

Test
Q.170 Easy Arrays & Strings
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.

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