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

A) Compile error
B) 0, 0
C) Runtime error.
D) the first two values entered by the user
Explanation: two values entered, 3rd will be null pointer assignment

Showing Answers 1 - 11 of 11 Answers

ashokiisc

  • Feb 1st, 2006
 

HiIn the statement scanf("%d %d"+scanf("%d %d", &i, &j)); the first two values are read into i and j. for the third value it is a null pointer assignment. so segmentation fault occurs at run time.--ashok kumar tellakula

  Was this answer useful?  Yes

The behavior is undefined.  There are not enough arguments for the given conversion specifiers in the scanf() calls (7.19.6.2.2).  It looks like the intent is for the inner call to scanf() to offset 2 characters into the first conversion specifier, effectively giving a call of scanf(" %d"), which invokes undefined behavior (assuming that even works; odds are it doesn't in general). 

Since the behavior is undefined, any of the listed results are allowed. 

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions