Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

499 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 291–300 of 499
Topics in C Programming
Q.291 Medium Arrays & Strings
Which of the following correctly declares and initializes a 2D array?
A int arr[3][3] = {{1,2,3}, {4,5,6}, {7,8,9}};
B int arr[3][3] = {1,2,3,4,5,6,7,8,9};
C Both A and B are correct
D Neither A nor B is valid
Correct Answer:  C. Both A and B are correct
EXPLANATION

Both syntax forms are valid in C. Elements can be provided in nested braces or as a linear list, and they fill row by row.

Take Test
Q.292 Medium Arrays & Strings
What will be the output of this code?
int arr[5];
for(int i=0; i
A 0 1 4
B 1 4 16
C 1 2 4
D 0 4 8
Correct Answer:  B. 1 4 16
EXPLANATION

Array values: arr[0]=0, arr[1]=1, arr[2]=4, arr[3]=9, arr[4]=16. Output is 1 4 16.

Take Test
Q.293 Medium Arrays & Strings
What is the time complexity of searching for an element in an unsorted array of size n?
A O(1)
B O(log n)
C O(n)
D O(n²)
Correct Answer:  C. O(n)
EXPLANATION

Linear search on unsorted array requires checking each element in worst case, giving O(n) time complexity.

Take Test
Q.294 Medium Arrays & Strings
What will the following code output?
char str[20];
strcpy(str, "Competitive");
strcat(str, " Exam");
printf("%s", str);
A Competitive
B Exam
C Competitive Exam
D Error
Correct Answer:  C. Competitive Exam
EXPLANATION

strcpy copies "Competitive" to str. strcat appends " Exam" to it, resulting in "Competitive Exam".

Take Test
Q.295 Medium Arrays & Strings
Consider: int *ptr = arr; where arr is an array. What does ptr[2] represent?
A Second element of array
B Third element of array
C Address of third element
D Pointer arithmetic error
Correct Answer:  B. Third element of array
EXPLANATION

ptr[2] is equivalent to *(ptr+2), which points to the third element (index 2) of the array.

Take Test
Q.296 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.297 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.298 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.299 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.300 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
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