Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

1,000 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 611–620 of 1,000
Topics in C Programming
Q.611 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.

Test
Q.612 Hard Functions
In the context of function pointers, what does the restrict keyword do?
A Restricts the pointer from pointing to different functions
B Tells the compiler that the pointer is the only way to access the data
C Makes the function inaccessible from other files
D Prevents pointer arithmetic
Correct Answer:  B. Tells the compiler that the pointer is the only way to access the data
EXPLANATION

The restrict keyword informs the compiler that the pointer is the sole means of accessing the data it points to, allowing for optimization. It's a hint for compiler optimization.

Test
Q.613 Easy Functions
What is the difference between declaring a function and defining a function?
A Declaration specifies the function signature; definition includes the function body
B They are the same thing in C
C Definition comes before declaration
D Declaration includes the function body; definition does not
Correct Answer:  A. Declaration specifies the function signature; definition includes the function body
EXPLANATION

A declaration tells the compiler about the function's signature (return type, name, parameters); a definition provides the actual implementation (function body).

Test
Q.614 Hard Functions
How are function arguments evaluated in C?
A Left to right (guaranteed order)
B Right to left (guaranteed order)
C The order is unspecified and implementation-dependent
D Based on the function's parameter list order
Correct Answer:  C. The order is unspecified and implementation-dependent
EXPLANATION

The C standard does not specify the order of evaluation of function arguments. The order is implementation-dependent and can vary between compilers.

Test
Q.615 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.

Test
Q.616 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.

Test
Q.617 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.

Test
Q.618 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.

Test
Q.619 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.

Test
Q.620 Easy Functions
Which keyword is used to pass arguments by reference in C?
A ref
B Pointers are used to simulate pass-by-reference
C reference
D &reference
Correct Answer:  B. Pointers are used to simulate pass-by-reference
EXPLANATION

C does not have a 'ref' keyword like C++. Pointers are used to achieve pass-by-reference semantics in C by passing the address of a variable.

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