Exforsys
+ Reply to Thread
Results 1 to 2 of 2

Reason for Output

This is a discussion on Reason for Output within the C and C++ forums, part of the Programming Talk category; I have a C program as for(i=1;0;i++) { printf("Hello"); } I thought there would be no output but I found ...

  1. #1
    cyrus is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    128

    Reason for Output

    I have a C program as
    for(i=1;0;i++)
    {
    printf("Hello");
    }

    I thought there would be no output but I found in the book I studied the answer given as Hello printed once. Is this a printing error or can anyone explain the reason for the same.


  2. #2
    Angela is offline Member Array
    Join Date
    Apr 2006
    Answers
    85
    The reason is the for loop gets executed once and the next time when it gets incremented only the condition fails. So Hello is printed once.


Latest Article

Network Security Risk Assessment and Measurement

Read More...