Programming Interview / Viva Q&A: 5 (while loop)

In this video tutorial lets understand the while loop a little better. We’ve posted source code of a C program below which has while loop. You need to guess the output of the program.

Related Read:
while loop in C programming

Guess output of the program

  1.    
  2.   
  3. int main()  
  4. {  
  5.     int count = 0;  
  6.   
  7.     printf("Start of program\n");  
  8.   
  9.     while(count <= 5);  
  10.     {  
  11.         printf("Count = %d\n", count);  
  12.         count = count + 1;  
  13.     }  
  14.   
  15.     printf("End of program\n");  
  16.   
  17.     return 0;  
  18. }  

Output:
Start of program

Since above C source code has semicolon(;) immediately after while(count <= 5) the control enters infinite loop or indefinite loop, and no other statements after the semicolon gets executed. And the program doesn’t get terminated with return 0.

C Programming Interview / Viva Q&A: 5 (While Loop)



YouTube Link: https://www.youtube.com/watch?v=fqYykTU-jrA [Watch the Video In Full Screen.]


If you remove the semicolon(;) after while(count <= 5) then the program will output numbers from 0 to 5 and the “End of program” statement.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert