strange scanf

  • Thread starter Shivanand Kadwadkar
  • Start date
S

Shivanand Kadwadkar

I was reading a forum there i found following program.

main()
{
int i, j;
scanf("%d %d"+scanf("%d %d", &i, &j));
printf("%d %d", i, j);
}

the above program is working fine.
Input:
4
5
6
output
6 5

this meas i=6 and j=5.

any idea why i=6 and j=5 ( i was thinking i should be i=5 and j=6)and
what the "+" is doing in scanf?

Thanks for sharing comments.
 
B

Ben Bacarisse

Shivanand Kadwadkar said:
I was reading a forum there i found following program.

main()
{
int i, j;
scanf("%d %d"+scanf("%d %d", &i, &j));
printf("%d %d", i, j);
}

the above program is working fine.

The program's meaning is undefined for at least two reasons. That means
that it is bound to work fine: since the program has no defined meaning,
anything it might do is as good as anything else.
Input:
4
5
6
output
6 5

I get something else (a segmentation fault) but that's also "working
fine".

A web search suggests this is an interview question, though where
answers are offered, none are correct.

<snip>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top