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

A) Runtime error. Access violation
B) Compile error. Illegal syntax
C) None of the above
D) Runtime error
Explanation: printf( ) prints address/garbage of i, scanf() dont have & sign, so scans address for i +1, -1 dont have any effect on code.

Showing Answers 1 - 10 of 10 Answers

pandi

  • Dec 30th, 2005
 

Ans   : Complier time error

  Was this answer useful?  Yes

srinivasan

  • Jan 5th, 2006
 

ans is -12

  Was this answer useful?  Yes

Chump

  • Jan 17th, 2006
 

Note that there is & which means it probably prints the address of i...n my guess is that + 1 has no effect on the output...
n regarding scanf - there is no & symbol...so still it will accept a value but not store it in i n my guess is that -1 has no effect on the code....
any comments

  Was this answer useful?  Yes

Vijay

  • Jan 23rd, 2006
 

Hey guys look at the code carefully it will give a segmentation fault as scanf expects the address of the variable in which the value will be scanned.

so the code should be like

scanf("%d",&i) -1;

  Was this answer useful?  Yes

sreelu

  • Mar 15th, 2006
 

ans is -12because it prints address of i.

  Was this answer useful?  Yes

vishal

  • Mar 27th, 2006
 

answer will be A)

As scanf expects address of i.

As soon as user enters any no. for i, compiler will try to access memory location equal to value of i and it will give acess voilation on windows and core dump on Solaris/Linux.

  Was this answer useful?  Yes

dev07

  • Jun 11th, 2006
 

answer is A) Runtime error. Access violation.

  Was this answer useful?  Yes

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