why the output of the following c programming is "one " can anyone explain?

78 Views Asked by At

`

#include <stdio.h>
int main ()
{
    int i=0;
    for(printf("one\n");i<3 && printf("");i++)
    {
        printf("Hi!\n");
    }
    return 0;
}

`

**AS we already know "shortcircuiting condition of logical and operator(&&) while we solving the condition of for looping the concept used is just an logical operators According to shortcircuting concept ,for i=0 i<3 condition is true && printf("") so in this statement left part is true therefore, right side condition is not evaluated

1

There are 1 best solutions below

0
Ken Y-N On

Looking at a reference for printf() we see:

  • On success, the total number of characters written is returned.

So, given i<3 && printf(""), the first time round i is 0, so i<3 is true, then printf("") prints zero characters, which returns 0, which is false, so the expression becomes true && false, thus false, so the loop terminates.