+ 5
What would be the output of following code?
#include<iostream.h> void main() { int a; a=1; cout<<++a+++a; }
8 Réponses
+ 9
one more thing void main is not valid c++ either. it can be used in some compilers but others will most certainly complain about it and not compile. int main() is the standard😊
+ 5
conio.h could not be found
clrscr is not defined
but it could be 6.
We should address the concerns here I guess.
Turbo c++ is very very obsolete. Please upgrade to something that supports 1998 standard c++ or higher.
Using multiple pre/post fix increments in a single statement results in undefined behaviour and is considered bad practise. Please do not do this.
+ 5
It will not be an error but some compilers will handle it differently than others. so the result maybe 5 on some compilers and 6 on others
But here is how it may work remembering that prefixes are evaluated before the expression is:
a=1
a+1 (++a) a = 2
a+1 (++a) a = 3
a + a ( 3 + 3)
+ 3
Compilation terminated
+ 2
Thanks Jay
+ 2
What if we write this code in code blocks removing conio.h and clrscr.. then what would be the result
Would it return error due to undefined behaviour
(And the answer in C++ was coming 6.. If anyone know how it is compiled then plz reply.)
+ 2
OK
Thanks for the help😊👍