Thursday, November 20, 2014

Wonderful undefined behavior of C language

Today, on stackoverflow I was reading an answer of a question on C language. The question is :

int main(){  
    int a=3;  
    printf("%d %d %d",++a,a,a++);
    return 0;
}  

What is the exact output of this program ?

You will be amazed to see the answer that I found on Stackoverflow. I am sharing the screenshot with you. The most interesting fact about the answer is that the answer is verified on Stackoverflow.






It is true that C language shows a lot of undefined behavior several times in increment and decrement operator operations and is totally compiler dependent. Also the printf statement shows undefined behaviour when you pass two functions for printing in printf.

The link for the above problem is given below:
http://stackoverflow.com/questions/12545976/order-of-argument-passing-in-c


No comments:

Post a Comment

See all Posts