what the hell is this and why
-
when you type a code int a =10; printf("%d %d %d",a++,a++,a++); returns o/p 12 11 10 can anybody pls xplain me why this o/p comes:doh:
-
when you type a code int a =10; printf("%d %d %d",a++,a++,a++); returns o/p 12 11 10 can anybody pls xplain me why this o/p comes:doh:
C++ don't tell in which order the parameters are passed... here your compiler passes the last parameter first, so, this is why the last a++ gives you 10. as you can see, never make such assertion in your code, and never write such code, because it will behave different ways depending on the compiler you built your code.
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
when you type a code int a =10; printf("%d %d %d",a++,a++,a++); returns o/p 12 11 10 can anybody pls xplain me why this o/p comes:doh:
keshava shukla wrote: int a =10; printf("%d %d %d",a++,a++,a++); returns o/p 12 11 10 Funny. I tested this and what I got to print out was: 10 10 10 That would be the behavior I would expect, since those are postfix (++) operators, they should be incremented after the printf() expression. I made sure and put a cout << a; statement after the printf() statement, and sure enough a was 13. Are you using C, or C++. The ++ is much more unpredictable in C. As the other person that responded said, just don't do it. If you have to, make three extra values, like a1, a2, a3, and increment a and assign it to each of those values and pass those into printf. Danny
-
keshava shukla wrote: int a =10; printf("%d %d %d",a++,a++,a++); returns o/p 12 11 10 Funny. I tested this and what I got to print out was: 10 10 10 That would be the behavior I would expect, since those are postfix (++) operators, they should be incremented after the printf() expression. I made sure and put a cout << a; statement after the printf() statement, and sure enough a was 13. Are you using C, or C++. The ++ is much more unpredictable in C. As the other person that responded said, just don't do it. If you have to, make three extra values, like a1, a2, a3, and increment a and assign it to each of those values and pass those into printf. Danny
thanks i think it will work