#Day8 'C' Coding Challenge

#Day8 'C' Coding Challenge

 What is the output of the below program?

#include<stdio.h> void main() { int var1; int var2 = 4; var1 = -var2--; printf("%d %d", var1, var2); }

---------------------------------------

The above code tests the following:

1. Operator precedence
2. Post Increment operation

---------------------------------------

In the above program, var1 is first assigned -var2, which meant var1 = -4
One the assignment is done, post increment of var2 shall be performed, no var2 = 3
So, print operation prints -4,3
First the var1=-var2 is executed as '-' has higher operator precedence than "--"

Post a Comment

0 Comments