LearnFrenzy
Sign in Take a free test
C

C Programming · Topic 16 of 23

C Loops Questions and Concepts

  • 4 exercises
  • 40 questions
  • ~60 min
  • Answers explained

Interview Questions

C Loops · Study material

C Loops Interview Questions and Answers

1. What is the difference between while and do-while?

A while loop tests its condition before each pass and may run zero times; do-while tests after, so its body runs at least once.

2. In what order are the parts of a for loop executed?

Initialisation once; then condition, body, update – repeated until the condition is false.

3. What does continue do in a for loop?

It skips the rest of the body and jumps to the update expression, then the condition is tested again.

4. How many loops does break exit?

Only the innermost enclosing loop (or switch).

5. How do you write an infinite loop?

for (;;) or while (1). They are used for servers, event loops and embedded main loops, and are left with break or return.

6. Why is for (unsigned i = n; i >= 0; i--) a bug?

An unsigned value is never negative, so the condition is always true; after 0, i wraps to UINT_MAX.

7. Why should a loop counter not be a float?

Values like 0.1 are not exact in binary, so the counter drifts and may skip the end value; the loop can run one time too many or forever.

8. What is the time complexity of two nested loops of n?

O(n²) – the inner body runs n × n times. If the inner loop starts at the outer index, it runs n(n + 1)/2 times, still O(n²).

9. Can the loop variable of a for loop be used after the loop?

Not if it is declared in the header (C99 and later): its scope ends with the loop. Declare it before the loop if you need its final value.

10. What is a sentinel value?

A special input value (such as −1) that marks the end of the data and stops the loop.

11. Why are macros written as do { … } while (0)?

So that a multi-statement macro acts as a single statement and needs a semicolon, keeping it safe inside if/else without braces.

12. Inside a switch in a loop, what do break and continue do?

break leaves the switch only; continue goes to the next pass of the loop, because switch does not handle continue.

Ready to test your Programming?

Timed online tests with instant scores and explanations.

About this section

About C Programming

C programming is the language most computer science courses start with and the foundation of operating systems, embedded devices and compilers. This section helps you learn C properly – data types, operators, control statements, functions, arrays, strings, pointers, structures, memory allocation and files – and then prove it with hundreds of practice questions explained line by line.

Why it matters

  • C teaches how a computer really works: memory, addresses and how data is stored
  • Pointers and memory questions are a favourite in written tests and technical interviews
  • Once you know C, learning C++, Java and Python becomes much easier
  • Embedded systems, operating systems and many companies' coding rounds still use C

Who it is for

  • School students (Class 11–12 computer science) building a strong programming base
  • College students (B.Tech, BCA, MCA, B.Sc CS) preparing for semester exams, lab work and viva
  • Freshers preparing for campus placements, aptitude-cum-coding tests and technical interviews
  • Anyone preparing for GATE CS or government IT exams

What every topic gives you

  • Study material in five tabs: concepts with runnable examples, coding techniques, programs, interview questions and a cheat sheet
  • MCQs that check your understanding of every concept
  • "Predict the output" puzzles – the trickiest part of written tests
  • "Find the error" programs that train you to spot bugs quickly
  • Complete programs with solutions and real output, verified on a compiler

Asked in

  • Campus placements
  • TCS, Infosys, Wipro tests
  • Technical interviews
  • GATE CS
  • University exams
  • Government IT exams

How to use this section

  1. Read the study material of a topic and run the examples yourself.
  2. Practise the four exercises – MCQs, output, errors, programs – and read every explanation.
  3. Test yourself with the timed online test, then revise the topics you got wrong.

Search LearnFrenzy

Esc

Quick links