Computing desk | ||
---|---|---|
< April 20 | << Mar | April | May >> | April 22 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
What is the output of following code?
#include <stdio.h>
void main(){
int a=5,v;
v=(++a)*(++a)+(++a);
printf("%d , %d",v,a);
}
When I compiled it , I get different result according to compiler.
In Turbo C ,I get 72,8 In Dev c++ and Code::Blocks (Based on GNU GCC), I get 57,8 In C4Droid I get 50,8
Which is correct and how? Can you explain this for me? Thanks — Preceding unsigned comment added by Amrit Ghimire Ranjit (talk • contribs) 04:52, 21 April 2016 (UTC)
v=(++a)*(++a)+(++a); Turbo C 1 4 2 5 3 : (8 * 8) + 8 = 72 GNU C 1 3 2 5 4 : (7 * 7) + 8 = 57 C4Droid 1 2 3 5 4 : (6 * 7) + 8 = 50
a
or accessing a
elsewhere in the same expression where it is updated are both cause for considering the operation to have undefined behavior. With undefined behavior, all bets are off. There is not even a guarantee that the results make any sense at all. A google of sequence point yields much further discussion. -- Tom N talk/contrib 06:45, 21 April 2016 (UTC)Actually, even void main()
is non-standard and might induce undefined behaviour by itself. main()
should be defined as int main()
or int main(int argc, char **argv)
. You still don't need to return anything from main()
, a missing return
statement from main()
is taken as return 0;
meaning success. JIP | Talk 21:04, 22 April 2016 (UTC)
Does Google Cloud Messaging work for endpoint devices in China? Many Google services are blocked in China, but some are not. I'd like to know whether Google Cloud Messaging is among the blocked services or not. Johnson&Johnson&Son (talk) 06:08, 21 April 2016 (UTC)