Wednesday, 6 August 2014

Find the output of the following program.


void main()
{
int i=10, j=2;
int *ip= &i, *jp = &j;
int k = *ip/*jp;
printf(“%d”,k);
}         
Answer:
Compiler Error: “Unexpected end of file in comment started in line 5”.
Explanation:
The programmer intended to divide two integers, but by the “maximum munch” rule, the compiler treats the operator sequence / and * as /* which happens to be the starting of comment. To force what is intended by the programmer,
int k = *ip/ *jp;           
// give space explicity separating / and *
//or
int k = *ip/(*jp);
// put braces to force the intention 
will solve the problem.  

No comments:

Post a Comment