Unit III · Viva Questions
Revise the concepts orally. Open the study answer for a detailed explanation.
Explain user-defined functions and their advantages.
- Does writing a function definition run its body?
- No. The body runs when the function is called.
- Why use meaningful function names?
- They help readers understand the task without reading every statement.
Distinguish a function declaration, definition and call with an example.
- Can parameter names be omitted in a prototype?
- Yes. int square(int); is a valid prototype.
- Does a missing function definition always produce a syntax error?
- No. A call can compile with a declaration but later fail during linking.
Explain the four categories of functions based on arguments and return values.
- Is printing a value the same as returning it?
- No. Printing writes output; returning supplies a value to the caller.
- Can a function with no parameters return a value?
- Yes. For example, int fixed_limit(void).
Explain actual arguments, formal parameters and communication between functions.
- Must argument and parameter names match?
- No. Their positions and compatible types matter, not matching names.
- Does C guarantee left-to-right evaluation of arguments?
- No. Avoid depending on that order.
Explain the return statement and return types in C functions.
- Can statements after an executed return run in that call?
- No. That call has already finished.
- What does return 0 from hosted main indicate?
- Successful program termination.
Explain call by value in C with an example.
- What is copied when a pointer is an argument?
- The pointer value, not automatically the entire pointed-to object.
- Can a function freely change its own integer parameter?
- Yes, provided the parameter is modifiable and the operation is valid.
Show how a function can change caller variables using pointer arguments.
- Why is a temporary variable used during the swap?
- It saves the first value before that object is overwritten.
- Is passing an address true pass by reference in C?
- No. The pointer value is passed by value.
Explain local scope, file scope and variable hiding with an example.
- Does hiding change the hidden object’s stored value?
- No. A new declaration only changes which object that name identifies in its scope.
- What scope do labels have?
- Function scope.
Distinguish scope, lifetime and linkage.
- Does a local static object have external linkage?
- No. A block-local static object has no linkage.
- Can an object exist when its name is not currently in scope?
- Yes. A local static object is an example.
Explain the auto storage class with an example.
- Must auto be written for every local variable in C11?
- No. It is normally the default.
- Why does this automatic counter restart at zero?
- Its initialisation is performed for a new automatic object on each call.
Explain the register storage class and its restrictions.
- Can a C11 register object be passed to scanf using its address?
- No. Its address cannot be taken with &.
- Does register preserve a value between calls?
- No. It has automatic storage duration here.
Explain local static variables and file-scope static declarations.
- Does static mean the name is visible everywhere?
- No. A local static name remains limited to its block.
- Can a file-scope function be static?
- Yes. That gives it internal linkage.
Explain extern declarations with an example.
- Where should a shared object usually be defined?
- In one source file, with compatible extern declarations where needed.
- Does extern allocate a fresh object on every function call?
- No. A declaration can refer to the same lasting object.
Compare auto, register, static and extern in C11.
- Are all static declarations identical in scope and linkage?
- No. Block-local static and file-scope static declarations differ.
- Is the initial value of every local int zero?
- No. Ordinary uninitialised automatic ints do not have a useful guaranteed initial value.
Explain const, volatile and restrict type qualifiers.
- Does volatile make count++ atomic?
- No. volatile does not provide atomicity or thread synchronisation.
- Is const a storage class?
- No. It is a type qualifier.
Explain the C preprocessor and its main directives.
- Is #include a runtime function call?
- No. It is a preprocessing directive.
- Does a numeric macro necessarily create a variable?
- No. It replaces tokens in the source.
Explain object-like and function-like macros with precautions.
- Does parenthesising a macro make i++ safe as a repeated argument?
- No. Repeated evaluation remains a problem.
- Can a compiler inline an ordinary function?
- Yes. A macro is not the only way to avoid call overhead.
Explain conditional compilation and header guards.
- Does #ifdef DEBUG fail when DEBUG is defined as 0?
- No. It tests whether the macro is defined.
- Does a header guard apply once across the whole executable?
- No. It controls repeated inclusion within each preprocessing translation unit.
Explain recursion, its base case and recursive case.
- Can recursion be indirect?
- Yes. One function can call another that eventually calls the first.
- Does every recursive function have exponential time?
- No. Complexity depends on the calls and work performed.
Write and explain a recursive C program to find factorial.
- Why reject a negative input before converting it to unsigned?
- The conversion could turn it into a large value outside the supported domain.
- Why do earlier factorial calls wait?
- They need the result of the smaller call to complete their multiplication.
Write a recursive C program to find the greatest common divisor using Euclid’s method.
- Why is division by zero avoided in gcd?
- The b == 0 base case is checked before evaluating a % b.
- Must a be larger than b at the first call?
- No. The first remainder step can handle the other ordering.
Compare recursion and iteration with reference to factorial.
- Is recursive factorial faster in growth rate than iterative factorial?
- No. Both take linear time under the same fixed-width arithmetic model.
- Does iteration remove integer overflow risks?
- No. The result type still has a finite range.