C Programming — Functions
C language from basics to advanced placement prep
100 Questions 10 Topics Take Test
Advertisement
Showing 21–30 of 100 questions in Functions
Q.21 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.

Take Test
Q.22 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.

Take Test
Q.23 Medium Functions
What will be the output of this code?
int counter = 0;
void increment() { static int count = 0; count++; counter++; }
main() { increment(); increment(); printf("%d %d", count, counter); }
A 0 2
B 2 2
C Compilation error - 'count' undeclared
D 2 0
Correct Answer:  C. Compilation error - 'count' undeclared
EXPLANATION

The static variable 'count' is local to increment() and inaccessible from main(). Trying to print 'count' causes compilation error: undefined identifier.

Take Test
Q.24 Medium Functions
Which of the following correctly declares a variadic function?
A int func(int x, ...);
B int func(...);
C int func(int ...x);
D int func(int x, int ...);
Correct Answer:  A. int func(int x, ...);
EXPLANATION

Variadic functions use ... syntax, and at least one named parameter must precede it. Option A is correct; Option B violates requirement of at least one named parameter.

Take Test
Q.25 Hard Functions
What happens when a function with variadic parameters is called with fewer arguments than expected?
A Compilation error occurs
B Remaining arguments are initialized to 0
C Undefined behavior - garbage values are read
D Function call is rejected at runtime
Correct Answer:  C. Undefined behavior - garbage values are read
EXPLANATION

Variadic functions (using ...) don't validate argument count. Calling with fewer arguments leads to undefined behavior as the function reads undefined values from stack.

Take Test
Q.26 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.

Take Test
Q.27 Hard Functions
What will this code output?
int x = 10;
int* getAddress() { return &x; }
main() { int *ptr = getAddress(); printf("%d", *ptr); }
A 10
B Address of x
C Undefined behavior (dangling pointer would occur if x was local)
D Compilation error
Correct Answer:  A. 10
EXPLANATION

Since x is static (global scope), returning its address is safe and the pointer remains valid. The output is 10. If x were local, it would be undefined behavior.

Take Test
Q.28 Medium Functions
Which approach correctly implements a function returning multiple values?
A Using a struct containing multiple fields
B Using pointers as output parameters
C Using global variables modified by function
D A and B are both correct approaches
Correct Answer:  D. A and B are both correct approaches
EXPLANATION

Both approaches are valid in C: returning a struct with multiple fields or using pointers as output parameters. Using globals is possible but not recommended.

Take Test
Q.29 Hard Functions
What does the restrict keyword do when used with pointer parameters in C99?
A Prevents the pointer from being modified
B Tells compiler that pointer is not aliased, enabling optimizations
C Restricts pointer to point only to local variables
D Makes pointer read-only
Correct Answer:  B. Tells compiler that pointer is not aliased, enabling optimizations
EXPLANATION

The restrict keyword (C99) is a promise to the compiler that the pointer is the only way to access that memory during its lifetime, allowing aggressive optimizations.

Take Test
Q.30 Medium Functions
Consider the function: void func(int *arr, int size). Which statement is correct?
A arr is a local copy of the original array
B arr receives the address of the first element, allowing modification of original
C The function cannot access the original array
D arr and size must be passed by pointers
Correct Answer:  B. arr receives the address of the first element, allowing modification of original
EXPLANATION

Array names decay to pointers in function calls. The parameter arr receives the address of the first element, so modifications affect the original array.

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