C Programming - Pointers - Discussion

Discussion Forum : Pointers - Find Output of Program (Q.No. 16)
16.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char str[] = "peace";
    char *s = str;
    printf("%s\n", s++ +3);
    return 0;
}
peace
eace
ace
ce
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
40 comments Page 3 of 4.

Akshay said:   1 decade ago
Whats the output if they ask like below.......
printf("%d\n", ++s +3); instead of;;
printf("%d\n", s++ +3);

K.MOUNIKA said:   1 decade ago
All this kind of expression which include + are calculated from right to left of (). thanks @Swathi.

Roshan Zameer said:   2 decades ago
Hi lavanya.

Since +3 is used you have to increment it. Then you ll reach 'ce'. So it will be printed.

Arpit said:   1 decade ago
Actually s++ = s+1 here use this fundamental s++ +3 means s = s+3.

So the answer is ce.

Ranu said:   1 decade ago
All this kind of expression which include + are calculated from right to left of ().

Mangesh said:   1 decade ago
@Monika : Thamk you so much for explaining in such a nice way.....

Swathi said:   1 decade ago
printf("%s\n", s++ +3); here y s++ is not incremented

Vicky said:   1 decade ago
Printf ("%c\n", s++ +3);// This will print only c right?

UmU said:   1 decade ago
@monika you done the good work thks. :).

Lavanya said:   2 decades ago
I need answer description for this.


Post your comments here:

Your comments will be displayed after verification.