Awesome C Exam Question
Heads up! This article was written over 16 years ago. While it may still be helpful, please verify any information, as my perspectives and practices may have evolved.
Working through some C example exam questions for my exam on Thursday Friday and @andyide found this little beauty.
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <stdio.h> | |
| int func (int a, int b) { | |
| static int c = 1; | |
| return a + b * (c *= -1); | |
| } | |
| int main () { | |
| int a = 2, b = 3; | |
| int c = func(a, b); | |
| a *= a++; | |
| b *= ++b; | |
| printf("%d %d %d %d\n", a, b, c, func(a, b)); | |
| } | 
Without cheating and running it through gcc, give it a dry run and see what you get. My first attempt was incorrect with 4 12 -1 16. Gutted.
(EDIT: For anyone who was wondering what the answer actually was, without compiling, click here. I didn’t want to post the spoiler in the post. That wouldn’t be any fun.)