char c "GATE2011";
char *p =c;
printf "%s", p+p 3 p 1 ;
=
the output is 2011
can any one explain how?
vgd 0 Newbie Poster
Recommended Answers
Jump to PostPlease post the entire code that will actually compile. That means adding all the parentheses, commas and semicolons, as well as the function.
Jump to PostThe program you posted is still wrong. The answer would be undefined because p[3] = the letter 'E' and p[1] is the letter 'A'. so p+'E'+'A' = p+69+65, or 127 bytes beyond the end of the buffer. Where did I get those numbers? From any ascii chart, like
Jump to Postits p+p[3]-p[1],not p+p[3]+p[1],hence 2011 is the output...
Not possible.
p[3] == '2' == 50 (see any ascii chart for values)
p[1] == 'a' == 97
Therefore: 50 - 97 == …
Jump to PostNot possible.
p[3] == '2' == 50 (see any ascii chart for values)
p[1] == 'a' == 97
Therefore: 50 - 97 == -47, which is a negative value, so the result of …
All 14 Replies
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
vgd 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
vgd 0 Newbie Poster
zaraki 0 Newbie Poster
smilenow 17 Newbie Poster
smilenow 17 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
smilenow 17 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Santi1986 0 Newbie Poster
smilenow 17 Newbie Poster
smilenow 17 Newbie Poster
Ancient Dragon commented: right +17
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.