Tutorials, Free Online Tutorials,It Challengers provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, core java, sql, php, c language etc. for beginners and professionals.

Breaking

C Aptitude Questions And Answers - EXPRESSIONS.

---------------------------------- Test Your "C" Skill --------------------------------------

EXPRESSIONS.



1.    
void main()
{
 static int a[20];
int x=0;
a[x]=x++;
printf(“\n %d  %d  %d”, a[0],a[1],x);
}

Output:- 0  0  1
This is what some compiler give others may give a different answer. The reason is that the same statement causes the same object to be modified or to be modified and then inspected, the behavior is undefined.

2.   
void main()
{
  int x=3;
  x=x++;
  printf(“%d”,x);
}

Output:- 4
 but basically the behavior is undefined because of the same reason as above.
  
3.
void main()
{
int x=2;
printf(“%d  %d”,++x,++x);
}
a  3  4
b  4  3
c  4  4
d  may be vary from compiler to compiler

Output:-d the order of evaluation of the arguments to a function call is unspecified.

4.
void main()
{
  int x=10,y=20,z=5,a
  a=x<y<z;
  printf(“%d”,a);
}
a 1
b 0
c error
d none of above.

Output:- a

5.
Are the following statements same?
 a<=20?b=30:c=30;
 (a<=20)?b:c=30;

Output:-No.

6.
can you suggest the other way of writing the following expression such that 30 is used only once
a<=20?b=30:c=30;

Output:- *((a<=20)?&b:&c)=30;

7.
Would the expression *p++ = c be disallowed by the compiler.

Output:-No. 
Because even the value of p is accessed twice it is used to modify two different objects p and *p.

 8.
In the following code in which order the functions would be called.
A=f1(23,65) * f2(12/4) + f3();
a.      f1,f2,f3.
b.     f3,f2,f1.
c.      The order may vary from complier to complier.
d.     None of above.

Output:-C. 
Here the multiplication will happen before the addition, but in which order the function would be called is undefined.

9.
What would be the output of the following program?
void main()
{
 int x=-3,y=2,z=0,m;
 m=++x && ++y || ++z;
 printf(“\n %d  %d  %d  %d”,x,y,z,m);
}

Output:-  2  3  0  1
 10.
What would be the output of the following program?
void main()
{
 int x=-3,y=2,z=0,m;
 m=++y && ++x || ++z;
 printf(“\n %d  %d  %d  %d”,x,y,z,m);.
}

Output:-  2  3  0  1

10.
void main()
{
 int x=-3,y=2,z=0,m;
m=++x || ++y && ++z;
printf(“\n %d %d %d %d”,x,y,z,m)
}

Output:- 2 2 0 1

11.
void main()
{
 int x=-3,y=2,z=0,m;
m=++x && ++y && ++z;
printf(“\n %d %d %d %d”,x,y,z,m)
}

Output:-  2 3 1 1

No comments:

Post a Comment