Home Subjects C Programming Functions

C Programming
Functions

C language from basics to advanced placement prep

100 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 71–80 of 100
Topics in C Programming
Q.71 Medium Functions
Which of the following correctly represents a callback function scenario?
A A function that calls itself recursively
B A function pointer passed as argument to another function
C A function that modifies global variables
D A function declared with extern keyword
Correct Answer:  B. A function pointer passed as argument to another function
EXPLANATION

A callback function is a function pointer passed to another function, which calls it at a later point in time.

Take Test
Q.72 Easy Functions
Consider: int func(int x) { return ++x; } What is the difference if we use x++ instead of ++x?
A No difference in return value
B ++x returns x+1, x++ returns original x
C x++ is faster than ++x
D Depends on compiler optimization
Correct Answer:  B. ++x returns x+1, x++ returns original x
EXPLANATION

Pre-increment (++x) increments and returns the new value, while post-increment (x++) increments but returns the old value.

Take Test
Q.73 Medium Functions
What happens if a function declared as returning int doesn't contain a return statement?
A Compiler error
B Returns 0 by default
C Returns undefined/garbage value
D Depends on the compiler implementation
Correct Answer:  C. Returns undefined/garbage value
EXPLANATION

Without an explicit return statement, the function returns whatever value is in the return register, which is undefined behavior.

Take Test
Q.74 Medium Functions
Which of the following is true about a static function in C?
A It cannot be called from other files
B It has only one instance throughout the program
C It is stored in static memory segment
D All of the above
Correct Answer:  A. It cannot be called from other files
EXPLANATION

A static function has file scope and cannot be accessed from other translation units, providing encapsulation.

Take Test
Q.75 Medium Functions
What is the correct way to declare a function that accepts variable number of arguments?
A void func(...);
B void func(int, ...);
C void func(int n, ...);
D Both B and C are correct
Correct Answer:  D. Both B and C are correct
EXPLANATION

Variadic functions require at least one named parameter before the ellipsis. Both options B and C follow the correct syntax.

Take Test
Q.76 Medium Functions
What will be printed by this code?
void func(int arr[10]) { printf("%lu", sizeof(arr)); }
int main() { int a[10]; func(a); }
A 40
B 10
C 8 (or 4 on 32-bit)
D Compiler error
Correct Answer:  C. 8 (or 4 on 32-bit)
EXPLANATION

When arrays are passed to functions, they decay to pointers. sizeof(arr) returns the size of the pointer, not the array.

Take Test
Q.77 Easy Functions
Which keyword is used to create a function that can be expanded inline by the compiler without actual function call overhead?
A extern
B static
C inline
D register
Correct Answer:  C. inline
EXPLANATION

The 'inline' keyword (introduced in C99) suggests to the compiler to replace function calls with actual code, reducing call overhead.

Take Test
Q.78 Easy Functions
What is the scope of a function parameter in C?
A Global scope
B File scope
C Function scope
D Block scope
Correct Answer:  C. Function scope
EXPLANATION

Function parameters have function scope, meaning they are accessible throughout the entire function body.

Take Test
Q.79 Medium Functions
In C, when a function is called with fewer arguments than declared, what happens?
A Compiler error occurs
B Runtime error occurs
C Garbage values are passed for missing arguments
D It compiles and runs without error if using old-style declarations
Correct Answer:  D. It compiles and runs without error if using old-style declarations
EXPLANATION

Old-style K&R C declarations don't perform argument checking, allowing calls with fewer arguments. Modern prototyped functions generate compiler errors.

Take Test
Q.80 Medium Functions
Which of the following correctly declares a function pointer that points to a function returning int and taking two int parameters?
A int (*funcPtr)(int, int);
B int *funcPtr(int, int);
C funcPtr *int(int, int);
D int funcPtr*(int, int);
Correct Answer:  A. int (*funcPtr)(int, int);
EXPLANATION

The correct syntax for function pointer is return_type (*pointer_name)(parameter_types). Option A is correct.

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