Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

490 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 291–300 of 490
Topics in C Programming
Q.291 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.

Test
Q.292 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.

Test
Q.293 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".

Test
Q.294 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.

Test
Q.295 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.

Test
Q.296 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.

Test
Q.297 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.

Test
Q.298 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.

Test
Q.299 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'.

Test
Q.300 Medium Functions
A function in C is declared as: int calculate(int *arr, int size). When this function modifies the array elements, what happens to the original array passed from the calling function?
A The original array is modified because arrays are passed by reference
B The original array remains unchanged; only the local copy is modified
C It depends on whether the pointer is declared as const
D The modification only affects the first element of the array
Correct Answer:  A. The original array is modified because arrays are passed by reference
EXPLANATION

In C, arrays decay to pointers when passed to functions, meaning the address is passed. Any modifications through the pointer affect the original array. This is effectively pass-by-reference behavior for arrays.

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