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 321–330 of 499
Topics in C Programming
Q.321 Medium Functions
What is the scope of a static variable declared inside a function?
A Local to the function, but retains value between calls
B Global scope with external linkage
C Only valid during function execution
D Accessible to all functions in the program
Correct Answer:  A. Local to the function, but retains value between calls
EXPLANATION

Static variables inside a function have local scope but static storage duration, meaning they retain their value between function calls and are initialized only once.

Take Test
Q.322 Medium Functions
In C, how many parameters can a function have at maximum?
A Up to 32 parameters
B Up to 127 parameters
C No predefined limit in C standard
D Only 8 parameters
Correct Answer:  C. No predefined limit in C standard
EXPLANATION

The C standard does not impose a maximum limit on the number of function parameters, though practical implementations may have compiler-specific limits.

Take Test
Q.323 Medium Functions
What is the output of this code? void swap(int a, int b) { int temp = a; a = b; b = temp; } int main() { int x = 5, y = 10; swap(x, y); printf("%d %d", x, y); }
A 10 5
B 5 10
C 0 0
D Garbage values
Correct Answer:  B. 5 10
EXPLANATION

This is call-by-value. The function swaps copies of x and y, not the originals. Original values remain unchanged.

Take Test
Q.324 Medium Functions
Which of the following correctly demonstrates inline function usage for optimization?
A inline void process() { } // Always inlined
B inline int square(int x) { return x*x; } // Compiler may inline
C void inline() { } // Syntax error
D Inline functions are not part of C standard
Correct Answer:  B. inline int square(int x) { return x*x; } // Compiler may inline
EXPLANATION

inline is a hint to compiler to expand function at call site. It's supported in C99+ and compiler decides whether to inline or not.

Take Test
Q.325 Medium Functions
What does variadic function mean in C?
A A function with variable argument list using ... (ellipsis)
B A function that changes its return type
C A function that can be defined multiple times
D A function with optional parameters
Correct Answer:  A. A function with variable argument list using ... (ellipsis)
EXPLANATION

Variadic functions accept variable number of arguments using ellipsis (...) and accessed with va_list, va_arg macros.

Take Test
Q.326 Medium Functions
Consider: void modify(int *ptr) { *ptr = 20; } int main() { int x = 10; modify(&x); printf("%d", x); }. Output?
A 10
B 20
C Garbage value
D Compilation error
Correct Answer:  B. 20
EXPLANATION

This is call by reference using pointers. The function receives address of x, dereferences and modifies it to 20.

Take Test
Q.327 Medium Functions
What is the purpose of the 'extern' keyword when used with a function?
A To declare a function defined in another file
B To make function local to current file
C To increase function scope
D To optimize function performance
Correct Answer:  A. To declare a function defined in another file
EXPLANATION

extern allows you to declare a function defined elsewhere, enabling its use across multiple translation units.

Take Test
Q.328 Medium Functions
Which statement about function parameters passed as arrays is correct?
A Arrays are passed by value with a copy created
B Arrays decay to pointers and are passed by reference
C Array size is mandatory in function parameters
D Multidimensional arrays cannot be passed to functions
Correct Answer:  B. Arrays decay to pointers and are passed by reference
EXPLANATION

Arrays in C decay to pointers to their first element, effectively making them pass-by-reference. Changes inside function affect original array.

Take Test
Q.329 Medium Functions
What will be the output of this recursive function? int fact(int n) { if(n
A 5
B 25
C 120
D Infinite recursion error
Correct Answer:  C. 120
EXPLANATION

This calculates factorial. fact(5) = 5*4*3*2*1 = 120. Base case n<=1 stops recursion.

Take Test
Q.330 Medium Functions
Consider the code: int calculate(int a, int b = 5) { return a + b; }. What is the issue?
A Default parameters are allowed in C
B Default parameters are NOT allowed in C (only in C++)
C Syntax is incorrect
D Return type is missing
Correct Answer:  B. Default parameters are NOT allowed in C (only in C++)
EXPLANATION

Default parameters are a C++ feature, not available in standard C. C requires explicit arguments for all parameters.

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