Skip to study material

PROGRAMMING FOR PROBLEM SOLVING

Unit I · Viva Questions

Revise the concepts orally, then follow the study link when you need a fuller explanation.

← Questions and answers

What is a programming language? Compare machine, assembly and high-level languages.

Is an assembler the same as a compiler?
No. An assembler translates assembly notation; a C compiler processes C language constructs.
Does high-level source run directly on every processor?
No. A suitable implementation and compatible environment are still needed.

Study this concept →

Explain the stages of program development with an example.

Why use 3.0 instead of 3 with an integer total?
The floating constant makes the division floating-point, preserving a fractional result.
Why is maintenance part of development?
Requirements and environments can change after the first working version.

Study this concept →

How do you create, compile and run a C program? Explain the translation stages.

What does -o hello specify?
It names the compiler’s output executable hello.
Can a missing function definition cause a link failure?
Yes. A declaration alone does not supply the implementation needed by the linker.

Study this concept →

Define an algorithm and explain its essential properties.

Can an algorithm exist without C code?
Yes. Natural language, pseudocode and flowcharts can describe an algorithm.
Is an unambiguous procedure automatically correct?
No. Its steps may be clear while its reasoning is wrong.

Study this concept →

Explain the advantages and limitations of algorithms.

Why trace an algorithm by hand?
A trace exposes how intermediate values and decisions produce the result.
Should every algorithm mention memory addresses?
No. Include only details needed for the problem and the intended level of explanation.

Study this concept →

What is a flowchart? Explain the standard symbols and drawing guidelines.

Where should “Print result” be placed?
Inside an input/output parallelogram.
Why label Yes and No branches?
Labels remove doubt about which path follows a true or false condition.

Study this concept →

What is pseudocode? Explain its conventions with an example.

Can pseudocode be compiled as C?
No. It must first be translated into valid C syntax.
Is ← a C assignment operator?
No. C uses = for simple assignment.

Study this concept →

Differentiate an algorithm, a flowchart and pseudocode.

Can a correct flowchart have incorrect accompanying pseudocode?
Yes. Each representation must be checked independently and compared.
Which format requires C header files?
None of these descriptions; header files belong to a C implementation.

Study this concept →

Develop an algorithm, pseudocode and flowchart to find the maximum of three numbers.

Why not initialise maximum to zero?
That would give a wrong result when all three inputs are negative.
How would the time change for n values?
Checking each value once would take O(n) time.

Study this concept →

Develop an algorithm and C program to swap two values using a temporary variable.

Does swapping change the types of a and b?
No. It exchanges the stored values in this example.
What happens when both values are equal?
The assignments still work; the final values remain equal.

Study this concept →

Develop an algorithm and flowchart to calculate the factorial of a non-negative integer.

Why initialise the product to 1?
One is the multiplicative identity; starting at zero would keep every product zero.
Can int store all factorials?
No. Every fixed-width integer type has a finite range.

Study this concept →

Develop a correct algorithm and flowchart to test whether an integer is prime.

Why must divisor 7 be tested for 49?
Because 49 is a perfect square and 7 is exactly its square-root divisor.
Why can 2 pass without entering the loop?
There is no possible divisor from 2 through √2.

Study this concept →

Develop an algorithm and flowchart to find the roots of a quadratic equation.

When does a quadratic have a repeated real root?
When a is non-zero and b² − 4ac equals zero.
Why reject a zero leading coefficient in the quadratic formula?
Because the equation is no longer quadratic and the denominator 2a would be zero.

Study this concept →

Develop an algorithm and flowchart to generate the first n Fibonacci terms.

Does n mean a term count or a maximum Fibonacci value here?
It is the number of terms to output.
Why save the Fibonacci sum before changing the pair?
The sum needs both old values; overwriting one first loses a required operand.

Study this concept →

Draw and explain a flowchart to determine whether an integer is even or odd.

Why test an odd integer by a non-zero remainder rather than remainder 1?
Negative odd integers can have remainder −1 under C11 integer division.
Why is zero classified as even?
It is divisible by two with no remainder.

Study this concept →

Develop an algorithm and flowchart to find the sum of two numbers.

Does a mathematically valid sum always fit int?
No. The type has a finite range, so a general implementation must prevent overflow.
Does summing two fixed inputs require a loop?
No. One addition suffices; summing an arbitrary number of inputs is a different problem.

Study this concept →

Develop pseudocode to find the largest value in a given set.

Why must this maximum input be non-empty?
The procedure needs a first actual value to initialise its candidate.
Must all maximum-scan inputs be stored in an array?
No. They can be read and processed one at a time using constant auxiliary space.

Study this concept →

Develop an algorithm to find the minimum and maximum in a set.

Can one input value be both the minimum and maximum?
Yes. In a one-element input, that value is both.
Why can input order change intermediate extrema without changing the final extrema?
Each step retains the extremes seen so far; after all inputs, the same complete set has been considered.

Study this concept →

Describe the background and important characteristics of C.

Does C require conio.h?
No. It is not a standard C header.
Does the same executable run on every operating system?
No. Executables depend on the target platform and environment.

Study this concept →

Explain the structure of a C program with a complete example.

Why is stdio.h included?
It provides declarations for functions such as printf.
Does a comment execute?
No. It documents the source without becoming a runtime action.

Study this concept →

What are tokens and identifiers? Explain identifier naming rules in C.

Are count and COUNT the same identifier?
No. C distinguishes letter case.
Can a variable be called student count?
No. A space separates tokens rather than forming one identifier.

Study this concept →

Explain the basic C data types, their ranges and how to check their sizes.

Which format prints a sizeof result?
%zu, because sizeof produces a value of type size_t.
Is double an exact representation of every decimal fraction?
No. Floating-point representations commonly approximate many decimal values.

Study this concept →

Define a variable. Explain declaration, initialisation and assignment.

Does int count; guarantee a local count starts at zero?
No. An automatic local object needs a valid initial value before it is read.
Does score = 80 change score from int to another type?
No. It stores a new value according to score’s declared type.

Study this concept →

Explain constants, literals and symbolic constant names in C.

What is the type of 2.0f?
float.
Is the terminating null character part of a string literal array?
Yes. It marks the end of the character sequence used as a C string.

Study this concept →

Explain printf and scanf with suitable format specifiers.

What does %.2f request in printf?
Two digits after the decimal point in the formatted output.
Why is & needed for a scalar scanf destination?
scanf must receive an address so it can store the converted value.

Study this concept →

Explain character input/output and safe whole-line input in C.

Does fgets always remove the newline?
No. It retains the newline if that newline is read into the buffer.
Why is scanf("%s", ...) unsuitable for a full name with spaces?
The %s conversion stops at whitespace.

Study this concept →

Classify the operators in C with examples.

Is ! unary or binary?
Unary: it acts on one scalar operand.
How many operands does ?: use?
Three: a condition and two alternative result expressions.

Study this concept →

Explain arithmetic operators, integer division and the remainder operator.

What is -7 % 2 in C11?
-1, consistent with division truncating toward zero.
Does double result = 7 / 2 produce 3.5?
No. Integer division produces 3 first, which is then converted to 3.0.

Study this concept →

Explain relational, equality and logical operators with short-circuit evaluation.

Does 2 && 7 produce 7?
No. Both operands are true, so the result is 1.
Why is 0 < x < 10 not a mathematical range test in C?
The first comparison produces 0 or 1, and that result is then compared with 10.

Study this concept →

Explain bitwise operators with a worked binary example.

When does XOR set a result bit?
When the corresponding operand bits differ.
Does ~12U flip only the last four bits?
No. It flips every bit of the unsigned int value.

Study this concept →

Explain the conditional operator ?: with an example.

What happens when the condition is zero?
The expression after the colon is selected.
Can both alternative expressions execute in one selection?
No. The conditional operator evaluates only the selected alternative.

Study this concept →

Differentiate prefix and postfix increment and decrement operators.

Do ++x; and x++; leave the same x when used alone?
Yes, provided the increment is valid and representable.
Can 5++ be used?
No. The operand must be a writable object, not a constant.

Study this concept →

Explain simple and compound assignment operators.

What does int x = 9; x /= 2; leave in x?
4, because the division uses integer arithmetic.
Can a const int be the destination of +=?
No. The destination must be modifiable.

Study this concept →

Define an expression and explain how its type affects the result.

Is total = 5 an expression in C?
Yes. It performs assignment and also has the assigned value as its result.
Does adding parentheses around a function argument force all argument evaluation order?
No. Parentheses for grouping do not add such a guarantee.

Study this concept →

Explain operator precedence and associativity with the correct precedence table.

Does left-to-right associativity mean the left function call always runs first?
No. It describes grouping, not a general order for function calls.
How does subtraction group in 10 - 3 - 2?
As (10 - 3) - 2, giving 5.

Study this concept →

Evaluate C expressions step by step and distinguish grouping from evaluation order.

Can a compiler choose different orders for f() + g()?
Yes, subject to the language rules; + alone does not sequence those calls.
What should an exam answer say for unsequenced changes to i?
Explain that the expression has undefined behaviour rather than inventing a fixed output.

Study this concept →

Explain implicit type conversion, integer promotions and mixed-type arithmetic.

What does int x = -3.9 store when representable?
-3, because truncation is toward zero.
Does converting to double always preserve every large integer exactly?
No. Floating-point precision is finite.

Study this concept →

Explain explicit type casting and distinguish casting before and after division.

Does (double)total modify total?
No. It produces a converted value for that expression.
Can a cast recover a fraction already lost by integer division?
No. Once 7 / 2 has produced 3, converting that result only gives 3.0.

Study this concept →