top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between for(;;) and while(true)? Which is preferable and why?

+3 votes
324 views
What is the difference between for(;;) and while(true)? Which is preferable and why?
posted Jan 3, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

–1 vote

Both the control statements are used for infinite loop. for(;;) is an unconditional loop statement. While needs a condition which can be controlled by user even at the run time. It is the matter of choice what a programmer likes on a particular condition. I prefer to use while (true) {} .

answer Jan 4, 2016 by Harshita
Similar Questions
+4 votes
#include <stdio.h>
typedef void (*ptr)(void);
void fun (void)
{
    printf("\n In fun\n");
}
int main()
{
    ptr funptr1, funptr2, funptr3;
    funptr1 = fun;
    funptr2 = *fun;
    funptr3 = &fun;
    funptr1();
    funptr2();
    funptr3();
    return 0;
}  

====================================================
OUTPUT :=>

    $ ./a.exe

     In fun

     In fun

     In fun

The address stored in funptr1, funptr2 and funptr3 is same why ??

...