What will be the result of the following code execution?
 
public static void Main(string[] args) 
{ 
      int k = 1; 
      Console.WriteLine(k++ + ++k);
}
 
Explanation
(k ++ + ++ k):
1) k ++ = 1 - result of the expression, but after k ++, k is increased by 1, i.e. k = 2. Thus we have (1 + ++ k), where k = 2.
2) (1 + (2 + 1)) = 4

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes