Solved

c output

Posted on 2007-03-26
2
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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 pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

726 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