GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 133 of 453    Print  

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.



  
Total Answers and Comments: 10 Last Update: December 23, 2008   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
December 30, 2005 00:08:28   #1  
pandi        

RE: Answer

Ans : Complier time error


 
Is this answer useful? Yes | No
January 05, 2006 09:17:55   #2  
srinivasan        

RE:
ans is -12
 
Is this answer useful? Yes | No
January 09, 2006 19:37:35   #3  
sujatham Member Since: January 2006   Contribution: 142    

RE: ans is (c)

Here printf() gives garbage value of i.

Here scanf() has no effect on function main.


 
Is this answer useful? Yes | No
January 17, 2006 09:48:48   #4  
Chump        

RE:
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

 
Is this answer useful? Yes | No
January 23, 2006 13:29:52   #5  
Vijay        

RE:

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;


 
Is this answer useful? Yes | No
March 15, 2006 05:08:22   #6  
sreelu        

RE:
ans is -12because it prints address of i.
 
Is this answer useful? Yes | No
March 27, 2006 08:56:19   #7  
vishal        

RE: Runtime error. Access violation

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.


 
Is this answer useful? Yes | No
June 11, 2006 08:25:43   #8  
dev07 Member Since: May 2006   Contribution: 1    

RE:

answer is A) Runtime error. Access violation.


 
Is this answer useful? Yes | No
May 27, 2008 07:14:07   #9  
punjalasampath Member Since: May 2008   Contribution: 1    

RE: main() { int i; clrscr(); printf("%d", &i)+1; scanf("%d", i)-1; }  
runtime error
 
Is this answer useful? Yes | No
December 22, 2008 13:30:30   #10  
Ajay Kanse Member Since: July 2007   Contribution: 22    

RE: main() { int i; clrscr(); printf("%d", &i)+1; scanf("%d", i)-1; }  
The printf will give some junk value (address) and scanf will wait for the input from user. once u enter a value u'll get Bus error(coredump).
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape