Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

499 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 311–320 of 499
Topics in C Programming
Q.311 Medium Functions
What is the default return type of a function in C (if not explicitly specified)?
A void
B int
C The compiler throws an error
D char
Correct Answer:  B. int
EXPLANATION

In older C standards (C89/C90), if a function's return type is not specified, it defaults to int. However, modern C99 and later require explicit return type declaration.

Take Test
Q.312 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.313 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.314 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.315 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
Q.316 Medium Functions
What is the primary advantage of using inline functions?
A They save memory by reducing code duplication
B They eliminate function call overhead by substituting code at call site
C They enable recursion without stack overflow
D They improve code readability
Correct Answer:  B. They eliminate function call overhead by substituting code at call site
EXPLANATION

Inline functions request the compiler to replace function calls with actual function code, eliminating call overhead. However, compiler may ignore inline suggestion.

Take Test
Q.317 Medium Functions
Which of the following is true about function pointers in C?
A They cannot point to built-in functions
B They enable dynamic function calls and callbacks
C They require special declaration syntax different from regular pointers
D They cannot be stored in arrays
Correct Answer:  B. They enable dynamic function calls and callbacks
EXPLANATION

Function pointers are powerful features enabling dynamic function selection at runtime, crucial for callbacks, function arrays, and design patterns like strategy pattern.

Take Test
Q.318 Medium Functions
Analyze the following pointer to function declaration: int (*ptr)(int, int);
A ptr is a function that returns int pointer
B ptr is a pointer to a function taking two int parameters and returning int
C ptr is an array of function pointers
D ptr is a function returning array of ints
Correct Answer:  B. ptr is a pointer to a function taking two int parameters and returning int
EXPLANATION

The parentheses around (*ptr) indicate ptr is a pointer. The remaining (int, int) shows it points to a function taking two int arguments and returning int.

Take Test
Q.319 Medium Functions
What is the difference between call by value and call by reference in C?
A Call by reference creates a copy; call by value passes address
B Call by value passes copy; call by reference passes address via pointers
C No difference; C uses only call by value
D Call by reference is faster
Correct Answer:  B. Call by value passes copy; call by reference passes address via pointers
EXPLANATION

C supports call by value (default) and call by reference (using pointers). Call by value passes a copy; call by reference passes the address allowing modifications to original.

Take Test
Q.320 Medium Functions
Which calling convention passes parameters through the stack from right to left?
A cdecl
B stdcall
C fastcall
D pascal
Correct Answer:  A. cdecl
EXPLANATION

The cdecl (C declaration) calling convention is the standard in C, pushing parameters onto the stack from right to left, with the caller responsible for stack cleanup.

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