Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

303 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 161–170 of 303
Topics in C Programming
Q.161 Easy Arrays & Strings
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'.

Take Test
Q.162 Easy Arrays & Strings
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).

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

Take Test
Q.164 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.

Take Test
Q.165 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.

Take Test
Q.166 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.

Take Test
Q.167 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.

Take Test
Q.168 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.

Take Test
Q.169 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.

Take Test
Q.170 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.

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