This question is very strong way to evaluate your idea about the increment/decrement unary operator in C. Being the most efficient way of increasing or decreasing a value, these operators are abandon in almost every piece of code. This question will enhance your concept about the Increment and Decrement operator in huge extent. But keep in mind that This question is not related to postfix and prefix types of these operator because these are extensively covered in almost all university courses.
What is the output of following code snippet?
I’m sure that you are aware of the inx/dcx unary operators. At a glance it may seem like here is a prefix increment operator in above expression. But if you explore it more precisely you will find something wrong.
Lets explore some facts about Increment operator.
- Increment or decrements operator can be only applied with variables so We can not use it with values, literals or expressions.
For example: a=3++ ; is totally invalid and will lead to compile time error.
- Another point is nesting of increment or decrement operator is not valid at all. That means ++(a++) is invalid expression.
- Also last thing it can be applied with float or double variables.
Now here In our code It violate the first fact mentioned above.
Therefor the above code lead to compile time error saying : error: lvalue required as increment operand
So here You exploit something about inx/dcx unary operator and hope you can give shut it down response in this kind of question.
Previously I have some Interview Questions about Size of Pointer. That may be very useful content if you are preparing for job or enhance your knowledge for any matter.
If you have any suggestion please drop a mail or feel free to comment.