Chapter - 4: The Loop Control Structure

How many times the while loop in the following C code will get executed?


D
Sections
7
Exercises
#include<stdio.h>
int main()
{
	int j = 1;
	while(j <= 255);
	{
		printf("%c %d",j,j);
		j++;
	}
	return 0;
}

Ans:

Infinite times. As the while loop is ended in the first line, as there's a semicolon after while statement, and the code below it doesn't come in the loop body. So those statements will never execute and the loop goes on till infinity.


© 2021 Garbage Valuegarbage value logo