![]() |
VOOZH | about |
Prerequisite : Pre-increment and Post increment
Question 1
What is the output of the above program?
Answer : y Explanation: The pointer 'p' points at the third location of the character array. The reason is that in the 'for' loop iteration, the value of the character pointer 'p' has been incremented thrice.
Question 2
What is the output of the above program?
Answer: o Explanation: When the character array 'ch' is passed as an argument to the function 'test()', the base address of the array 'ch[]' is passed. The variable 'c' in the function 'test()' points at the second location of the array. And then it decrements by 1 pointing to 'o'.
Question 3
What is the output of the above program if the ASCII values of characters 'x'=120, 'y'=121, 'z'=122?
Answer : 231Explanation: The pointer ptr points to 'x'.
Step1: Since, it is a post-decrement operation, hence the value remains 120 and is decremented later.
Step2 :The pointer str1 points at 'x'. Since ++ and * have same precedence level evaluation starts from Right to Left. For the expression ++*str1, Firstly *str1 is evaluated which gives 120 i.e. ASCII Equivalent of x. Next we evaluate the prefix increment ++120 = 121. Hence the final result is (120+121)-10=131
Question 4 - What will be the output of following Program?
Output :
[L]
[i]Explanation : Since the priority of both ā++ā and ā*ā are same so processing of ā*ptr++ā takes place from right to left. Going by this logic, ptr++ is evaluated first and then *ptr. So both these operations result in āLā. Now since a postfix ā++ā was applied on ptr so the next printf() would print āiā.
Question 5 - What will be the output of following Program?
Answer:311