Could anyone explain to me why it prints 32 and the overall concept of how this works?
#include <stdio.h>
int main()
{
    int a=1;
    for (printf ("3"); printf ("2"); printf ("1"))
    return 0;
}
                Proper indentation would make it clearer:
#include <stdio.h>
int main()
{
    int a=1;
    for (printf ("3"); printf ("2"); printf ("1"))
        return 0;
}
So the following happens:
a is initialized to 1. I don't know why this variable exists, since it's never used.for executes its initialization statement, printf("3");. This prints 3.for evaluates its repetition condition, printf("2"). This prints 2 and returns the number of characters that were printed, which is 1.return 0;. This returns from main(), thus ending the loop.Since the loop ends, we never evaluates the update expression, printf("1"), so it never prints 1. And we get no repetition of anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With