Sentinel loops

In sentinel loops we don’t know that how many no. of times the loop will work!

That means that a sentinel loop can be regarded as infinite, indefinite loop.

For Eg:

main()

{

int x=1;

while (x=1)

{

printf("This is an infinite loop!");

}

}

 

Output will be an infinite loop printing “This is an infinite loop!” infinitely!! 🙂

Precedence order in aritmetic operators in c

Precedence of aritmetic operators is as follows:

*   /   % +   –       –> Multiplication, division, modulo, addition & subtraction at the end!

For Eg:

If we run a program with following code:

main()
{
int x;
x = 5/4+3*2-4%2+5/2;
printf("%d",x);
}

It will solve the following way:

x= 5/4+6 – 4%2 + 5/2

Next,

x=1 + 6 – 4%2 + 2

5/4 will come out to be 1 & 5/2 will come out to be 2 because we have declared x as integer not as a float!

Next,

x=1+6-0+2

Finally,

x=72=9!

This implies x=9 will be the answer and hence output will be:

9