ok..then
c=++a + ++a + ++a
should give the output c=24
but its c=22.
???

Undefined behavior is the SchrÃ¶dinger's cat of programming. The result of an undefined expression could be anything until you actually run it, and the result you get in practice depends on too many factors to be predictable. Results that aren't predictable and can't be controlled are undesirable, right?

The explanation is only weird for the first time. i.e. ++a + ++a = 14
But if you debug and see the value of a, it will be 7 and after that if u add another ++a to it the answer is 22 and the final value of a is 8 and it increments by 1 for everytime you add ++a

i.e.
++a + ++a = 14 final value of a=7
++a + ++a + ++a = 22 final value of a=8
++a + ++a + ++a + ++a = 31 final value of a=9
++a + ++a + ++a + ++a + ++a = 41 final value of a=10 and so on....

So lets say you add one ++a to to the first expression and you get the result 22 i.e. 14+8=22 and it continues like this.

The reason for making ++a + ++a = 14 is:
Lets say you want to print the value of a and since there are 2 values of a so the makers of 'C' decided to give both the a's the final value i.e. 7 in this case and added them to give 14.

I hope I am able to give some justification to it.

The result of an undefined expression could be anything until you actually run it, and the result you get in practice depends on too many factors to be predictable. Results that aren't predictable and can't be controlled are undesirable, right?

The value cannot be determined with any surety. See this

Is C similar to C# (C-sharp); or are they completely different ? I was wondering if I should begin learning C# and the transition to C will be a tad ...

Write a program that displays all numbers divisible by 3 and 4 within a range entered by user. Display five numbers per line. Numbers are separated by exactly two spaces. ...

Hi guys. I am trying to create a program where the user inputs an integer and the program will cout the nth prime number. Unfortunatly when I try to cout ...