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 301–310 of 499
Topics in C Programming
Q.301 Medium Functions
A function in C is declared as: int calculate(int *arr, int size). When this function modifies the array elements, what happens to the original array passed from the calling function?
A The original array is modified because arrays are passed by reference
B The original array remains unchanged; only the local copy is modified
C It depends on whether the pointer is declared as const
D The modification only affects the first element of the array
Correct Answer:  A. The original array is modified because arrays are passed by reference
EXPLANATION

In C, arrays decay to pointers when passed to functions, meaning the address is passed. Any modifications through the pointer affect the original array. This is effectively pass-by-reference behavior for arrays.

Take Test
Q.302 Medium Functions
Which of the following demonstrates proper use of the return statement in error handling?
A return NULL; for pointer functions to indicate failure
B return -1; for integer functions to indicate error status
C Use dedicated error codes or special return values to indicate success/failure
D All of the above are valid approaches
Correct Answer:  D. All of the above are valid approaches
EXPLANATION

All three approaches are valid for error handling in C. Functions typically return NULL for pointers, negative values for integers, or use predefined error codes to indicate failure states.

Take Test
Q.303 Medium Functions
What is the purpose of function inlining in modern C compilers?
A To increase code size for better readability
B To reduce function call overhead by replacing calls with function body
C To prevent function pointers from working
D To enforce external linkage
Correct Answer:  B. To reduce function call overhead by replacing calls with function body
EXPLANATION

Inlining substitutes a function call with the actual function body at compile time, eliminating function call overhead. This is a compiler optimization for performance-critical code.

Take Test
Q.304 Medium Functions
Consider a function that modifies an array passed as a parameter. Which statement is true?
A The array is passed by value, so modifications don't affect the original
B The array decays to a pointer, so modifications affect the original array
C Arrays cannot be modified within functions
D The const qualifier must be used to modify arrays in functions
Correct Answer:  B. The array decays to a pointer, so modifications affect the original array
EXPLANATION

When an array is passed to a function, it decays to a pointer to its first element. This means modifications to array elements affect the original array outside the function.

Take Test
Q.305 Medium Functions
What happens if a function is declared but never defined in C?
A The compiler throws an error immediately
B The program compiles but fails at link time
C The program executes without issues
D The compiler generates a default implementation
Correct Answer:  B. The program compiles but fails at link time
EXPLANATION

If a function is declared but not defined, the compiler generates code to call it (compilation succeeds), but the linker fails to find the function definition, resulting in a linker error.

Take Test
Q.306 Medium Functions
Which of the following is a valid way to return multiple values from a function in C?
A Using a struct to encapsulate multiple values
B Using pointers to modify caller's variables
C Using global variables
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

C provides multiple methods to return values: structs for encapsulation, pointers for indirect modification, and global variables (though not recommended). All three are technically valid approaches.

Take Test
Q.307 Medium Functions
What is the primary purpose of function pointers in C?
A To allocate memory dynamically
B To provide polymorphism and dynamic function dispatch
C To declare static functions
D To prevent function inlining
Correct Answer:  B. To provide polymorphism and dynamic function dispatch
EXPLANATION

Function pointers enable polymorphism by allowing runtime selection of which function to call. They are crucial for implementing callbacks and dynamic function dispatch.

Take Test
Q.308 Medium Functions
Which statement about extern functions is correct?
A extern functions can only be used within the same file
B extern functions are accessible across multiple translation units
C extern functions must be defined in the header file
D extern is mandatory for all function declarations
Correct Answer:  B. extern functions are accessible across multiple translation units
EXPLANATION

extern functions have external linkage and can be accessed from other translation units. It's the default linkage for functions declared outside a file.

Take Test
Q.309 Medium Functions
What does the const qualifier do when applied to function parameters?
A Makes the parameter immutable within the function
B Makes the parameter a global constant
C Prevents the function from being called multiple times
D Has no effect in function parameters
Correct Answer:  A. Makes the parameter immutable within the function
EXPLANATION

When const is applied to a function parameter, it prevents modification of that parameter within the function body, making it immutable for the duration of the function.

Take Test
Q.310 Medium Functions
Which of the following correctly demonstrates function recursion termination?
A A recursive function must always have a return statement
B A recursive function must have a base case to prevent infinite recursion
C Recursion automatically terminates after 100 calls
D The compiler prevents infinite recursion
Correct Answer:  B. A recursive function must have a base case to prevent infinite recursion
EXPLANATION

A base case is essential in recursive functions to provide a stopping condition. Without it, the function will cause stack overflow. The base case ensures recursion terminates properly.

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