20120118

How to use for loop in C++ CPP C

//==========================
//What will be the out put in C++, C or CPP
//1.Tricky for loop program
===========================
#include<stdio.h>
int main()
{
int i;
for(i=0;i<=5;i++); //when i=6 condition will become false and
                              //control flow will go next stmt to print once
        {

        printf("\n %d. Sonys",i);
        }
return 0;
}
//=======================================
//2. Tricky for loop Program

//=======================================
#include<stdio.h>
int main()
{
int i;
for(;;)//infinite loop infinite times
           //Manoj gets printed till stack over flow
        {
        printf("\n %d. Sonys",i);
        }
return 0;
}
//=======================================
//3. Tricky for loop Program

//=======================================
#include<stdio.h>
int main()
{
int i;
for(;;); //infinite loop within without increment
             //so control will not come out of loop and no o/p
        {
        printf("\n %d. Sonys",i);
        }
return 0;
}
Previous                             Home                               Next

No comments:

Post a Comment