简体   繁体   中英

How this C program is work?

void main()
{
long x;
float t;
scanf("%f",&t);
printf("%d\n",t);
x=90;
printf("%f\n",x);
{
    x=1;
    printf("%f\n",x);
    {
        x=30;
        printf("%f\n",x);
    }
    printf("%f\n",x);
}
    x==9;
    printf("%f\n",x);
}

For I/P 7 it print 0 and six times 7. How this code is working? i know that behavior is undefined if we print variable with other than corresponding format specifier , but why this print 6 everytime ?

"Undefined behavior" is just that -- undefined. The fact that it's undefined makes "why is it doing that?" an invalid question.

Without proper format specifiers its obvious that the output will be erratic. As to "why" this happens rests on the compiler to decide.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM