AD1

Saturday, 29 April 2017

Find the output of the following code


Answer
i

Explanation 

char c=++*p++
this statement will be parsed as follow 
1)p++ p which is a char pointer is post incremented so p still points to 'h'
2)*p++ p is dereferenced to get value 'h'
3)++'h' is i

note:this result is highly compiler dependent , some compilers may fail to compile this code and others may get you this output

advise : never write a code which seems to be ambiguous and compiler dependent




No comments:

Post a Comment