Code:printf("\n%d",printf("%d %d",2,2)&printf("%d%d ",2,2));
Code:printf("\n%d",printf("%d %d",2,2)&printf("%d%d ",2,2));
understood..2 2222
Now change the values in the printfs to 10s.... what do you get?
But I'm just a bit curious... what's with all this screwball code you keep coming up with?
Seriously... nobody in their right mind would ever use code like this in a real-world program...
actually i am solving some c questions which are usually asked in interviews.i am not doing those programs..the above qn is AMAZON written question.
if u know the answer help to others..otherwise dont comment anyone...
The thing that worries me the most is that you believe there is a question in your first post.
1) DO NOT EVER presume to tell me what to do.
2) If you are getting questions like that in job interviews, you really don't want to work there. Any company producing code with stuff like that in it is probably producing crap software that you don't want your name connected to. One of the hardest lessons in technical trades is that 50% of your perceived "hirability" is entirely based upon reputation.
3) It's "you" ... not "u"... I am a person not a letter from the alphabet.
4) If you are getting questions like that and can't answer them on your own... maybe you don't deserve the job.
I dont really understand these question coming here, why cant you (the OP) try compile it to himself and find out the answer. The board isn't like compiler where you pump in some code and we compile and provide you the answer.
On the other note, i do like this interview question. Specially the '&'.
ssharish
Last edited by ssharish2005; 07-16-2011 at 10:08 AM.
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein
If the interview question is "what is the output of this line?", then simply compiling and running the code will not give a complete answer because of implementation defined behaviour. But...Originally Posted by ssharish2005
We don't actually know what is the question.Originally Posted by ssharish2005
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
>We don't actually know what is the question.
Rather the code/statment i should have said.
ssharish
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein
Yeah, every interview question should be "what is the result of this statement that is using undefined behavior?" How ridiculous.
I'd like to see where/how this question is related to Amazon.
Interesting enough the question is:
This supposedly is a Citrix question according to Amazon. I found a reference to it on Amazon but the actual question was here believe it or not.1. What is the output of this statement ?
Printf(“%d”,printf(“%d %d”,2,2) & printf(“%d %d ”, 2, 2));
a. 22222
b. 22221
c. It will give an error during compilation
Still the OP could bother to actually post a question and even provide his attempt at coming up with why. I have heard of crazy interview questions before from my buddy who works in the field.
Well since the format strings contain space, and the return result of printf() is normally the number of characters printed, the final value isn't going to be 2.
In fact, the posted example for "citrix" is the result of 3 & 4, which is zero.
Gotta love "clever" quiz questions falling into their own trap of being too clever for their own good.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.