Solved

c output

Posted on 2007-03-26
2
242 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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.

821 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