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 171–180 of 291
Topics in C Programming
Q.171 Easy Arrays & Strings
What will be the output of strlen("Hello") in C?
A 4
B 5
C 6
D Error
Correct Answer:  B. 5
EXPLANATION

strlen() returns the length of the string excluding the null terminator '\0'. "Hello" has 5 characters.

Test
Q.172 Easy Arrays & Strings
What is the correct way to declare a 1D array of 10 integers in C?
A int arr[10];
B int arr(10);
C int arr{10};
D int [10]arr;
Correct Answer:  A. int arr[10];
EXPLANATION

In C, arrays are declared with the syntax: datatype arrayname[size]. Option A follows the correct syntax.

Test
Q.173 Easy Functions
Consider the function declaration: void func(int x); and later in the code: int result = func(5);. What will be the compilation result?
A Compilation error because func returns void but is assigned to an int variable
B Compilation warning but will compile successfully; result will be undefined
C Successful compilation and result will be 5
D Runtime error will occur
Correct Answer:  A. Compilation error because func returns void but is assigned to an int variable
EXPLANATION

A void function cannot return a value. Attempting to assign the return value of a void function to a variable will cause a compilation error in standard C compilers.

Test
Q.174 Easy Functions
What is the difference between declaring a function and defining a function?
A Declaration specifies the function signature; definition includes the function body
B They are the same thing in C
C Definition comes before declaration
D Declaration includes the function body; definition does not
Correct Answer:  A. Declaration specifies the function signature; definition includes the function body
EXPLANATION

A declaration tells the compiler about the function's signature (return type, name, parameters); a definition provides the actual implementation (function body).

Test
Q.175 Easy Functions
Which keyword is used to pass arguments by reference in C?
A ref
B Pointers are used to simulate pass-by-reference
C reference
D &reference
Correct Answer:  B. Pointers are used to simulate pass-by-reference
EXPLANATION

C does not have a 'ref' keyword like C++. Pointers are used to achieve pass-by-reference semantics in C by passing the address of a variable.

Test
Q.176 Easy Functions
What is the scope of a static function in C?
A Global scope across all files
B Limited to the file in which it is defined
C Limited to the function block only
D Available to all functions in the current block
Correct Answer:  B. Limited to the file in which it is defined
EXPLANATION

A static function has internal linkage and is limited to the file in which it is defined. It cannot be accessed from other translation units.

Test
Q.177 Easy Functions
Which of the following is a correct function prototype in C?
A int func();
B func int();
C int func(void) { }
D func (void) int;
Correct Answer:  A. int func();
EXPLANATION

A function prototype must have the return type first, followed by the function name and parameter list in parentheses. Option A is the correct syntax.

Test
Q.178 Easy Functions
In C, what is the purpose of the return statement in a void function?
A It is optional and not needed
B To return 0 by default
C To exit the function immediately without returning a value
D To cause compilation error if used
Correct Answer:  C. To exit the function immediately without returning a value
EXPLANATION

In void functions, return statement (without value) can be used to exit the function prematurely. It's optional at the end since function exits automatically.

Test
Q.179 Easy Functions
What is the output of this recursive function?
int fact(int n) { if(n
A 24
B 10
C 12
D Stack overflow
Correct Answer:  A. 24
EXPLANATION

fact(4) = 4*fact(3) = 4*3*fact(2) = 4*3*2*fact(1) = 4*3*2*1 = 24. This is a proper factorial implementation with correct base case.

Test
Q.180 Easy Functions
What will be the output of the following code?
int add(int a, int b) { return a + b; }
int main() { printf("%d", add(5, add(3, 2))); return 0; }
A 10
B 8
C Compilation error
D 5
Correct Answer:  A. 10
EXPLANATION

Inner add(3,2) returns 5, then add(5,5) returns 10. Functions can be nested in arguments as long as return type matches parameter type.

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