Output of C programs | Set 39 (Pre Increment and Post Increment)
Prerequisite : Pre-increment and Post increment
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.
What is the output of the above program?
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’.
What is the output of the above program if the ASCII values of characters ‘x’=120, ‘y’=121, ‘z’=122?
Answer : 231
Explanation: 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 str points at ‘x’. The increment operation moves the pointer to the next location and now it points to ‘y'(i.e., 121) is substituted here. So, finally, i = 120 +121 – 10 = 231.
Question 4 – What will be the output of following Program?
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?
This article is contributed by Brahmani Sai. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.