
- Forum
- Programming Talk
- C and C++
- What is the ouput?
What is the ouput?
This is a discussion on What is the ouput? within the C and C++ forums, part of the Programming Talk category; int main() { int i=5; printf("\n%d",++i + ++i + ++i + ++i + ++i ); } What will be the ...
-
What is the ouput?
int main()
{
int i=5;
printf("\n%d",++i + ++i + ++i + ++i + ++i );
}
What will be the result of this code using UNIX OS with CC compiler? Howabout if a TC compiler is used, what will it display? If there is any difference, why is it that way?
-
Hi,
The answer for both would be the same. The output for the program is 50. It gets executed as follows:
I gets initialized to 5 and then among + and the increment operator ++, the increment operator ++ takes higher priority. And so i get increment as many times as ++ is encountered. So gets incremented 5 times which gives value of i as 10. Then get added five times which results in output 50 to be printed.
Regards,
Blenda
-
07-13-2006, 10:20 PM #3
Hi Adrian,
I belive this is the answer for your question.
int main()
{
int i=5;
printf("\n %d", ++i + ++i + ++i + ++i + ++i );
// 6 + 7 + 8 + 9 + 10 =40
printf("\n %d", ++i + ++i + ++i + ++i + i++ );
// 6 + 7 + 8 + 9 + 9 =39
}
So, the preincrement operator works first and then ant other task..... from L to R
regards,
SVS.Aditya
-
Sponsored Ads

Reply With Quote





