Solved

c output

Posted on 2007-03-26
2
238 Views
Last Modified: 2010-04-15
the output 4 the following code:

main()
{
char *p="ayqm";
char c;
c=++*p++;
printf("%c",c);
}

when i do this i get some windows error q60.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
the answer given by the author is 'b'.can ne1 please explain this?
0
Comment
Question by:shilpi84
2 Comments
 
LVL 24

Accepted Solution

by:
fridom earned 500 total points
ID: 18793946
what shoulc ++*p++ do? That code will not work.

The claims of the author are wrong and well it just shows misuse of C
Howerver the idea is that p is dereferences so it yield a
after that p should be advances by one step (but that will surely not work that way)
and after that the dereferences parameter is incremented
that means after 'a' follows 'b'
But that is just the idea and that simply does not work, I doubt that any C compiler will give the "result" the author claims it does.

It's exactly that kind of programming that has given C programign such a bad reputation. Will you win anything with that obfuscation? why not write it simply
c = *p++;
c++;
?
Ah yes and with buffered output you will not see anything printed at all.

This code is just BBB (BadBeyondBelief)

Regards
Friedrich
0
 

Author Comment

by:shilpi84
ID: 18794122
thanks 4 ur guidance:)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now