NEW
Font size
WorksheetsC Programming Worksheet Questions
Total questions: 25
Worksheet time: 13mins
What is the output of the following C code?
#include
97.000000
a
0.000000
Compilation error
Which keyword is used to explicitly exit a loop or switch statement?
continue
exit
break
return
Which of the following is a derived data type in C?
int
char
array
double
What is the value of a after the following code snippet executes? int a = 10; a += 5;
5
10
15
Undefined behaviour
What is the output of the following C code snippet?
#include
1
0
-1
Error
Which of the following is the correct syntax for the conditional (ternary) operator in C?
condition < expression1 ? expression2;
condition ? expression1 : expression2;
condition : expression1 ? expression2;
condition ? expression1 < expression2;
Which loop is used when you want to iterate through a range of values and know the number of iterations beforehand?
for loop
while loop
do-while loop
none of the above
How can you exit a loop prematurely if a certain condition is met?
using the continue statement
using the break statement
using the return statement
using the exit statement
What is the purpose of the continue statement in a loop?
to exit the loop
to skip the rest of the current iteration and move to the next iteration
to repeat the current iteration
to start a new loop
In situations where we need to execute body of the loop before testing the condition, we should use __________.
for loop
while loop
do while loop
nested for loop
What is the index number of the last element of an array with 29 elements?
29
28
0
Programmer-defined
What will sizeof(arr) return if arr is declared as int arr[5];?
5
10
20
Compiler error
What is the output of this code? int arr[3] = {10}; printf("%d %d %d", arr[0], arr[1], arr[2]);
10 10 10
10 0 0
0 0 0
Garbage values
Which of the following is a valid array initialization?
int arr[] = {1, 2, 3};
int arr[3] = {1, 2, 3};
Both a and b
Neither a nor b
What is the index of the first element in a C array?
0
1
-1
Depends on compiler
Which header file is required to use string functions like strlen(), strcpy(), and strcat()?
stdlib.h
string.h
stdio.h
conio.h
What is the correct way to declare a string in C?
char str[] = "Hello";
string str = "Hello";
Which of the following functions is used to find the length of a string?
strlen()
strlength()
length()
str_len()
The function __________ is used to copy one string to another in C.
strcpy
strcat
strrev
strcmp
What is the output of the following code? char str[10]; strcpy(str, "Hello"); printf("%s", str);
Error
Garbage value
Hello
Hell
What will be the output of the following code? int add(int a, int b) { return a + b; } int main() { printf("%d", add(2, 3)); return 0; }
2
3
5
Error
Which of the following is true about recursion in C?
Every recursive function must have a base case
Recursion is faster than loops
Recursion cannot use global variables
Stack is not used in recursion
What is recursion?
A function that calls itself
A function that returns a pointer
A function that calls another function
A function with no return type
What is the base condition in recursion?
The first condition
The stopping condition
The return type
None of the above
What is the correct syntax to declare a function in C?
function int myFunc();
int myFunc();
declare int myFunc();
int = myFunc();
