Monday, January 5, 2009

C programming language quiz with solution

What will be output ?
Q(1)

void main()
{
float k=25.5f;
int x=5;
clrscr();
printf("%d",k%x);
getch();
}
Q(2)

void main()
{
int x=5;
float r=5.0;
clrscr();
printf("%x %X %o",sizeof(x,r),sizeof(r,x),sizeof(sizeof(5.0)));
getch();
}
Q(3)

void main()
{
int y=15,z=25;
function(&y,&z);
clrscr();
printf("%d\t%d",z,y);
getch();
}
function (int *p,int *q)
{
return(*p=(*p+*q)-(*q=*p));
}
Q(4)

void main()
{
int a=-1;
static int count;
clrscr();
while(a)
{
count++;
a&=a-1;
}
printf("%d",count);
getch();
}
Q(5)

void main()
{
typedef float arr[10];
arr b={2,4,6};
clrscr();
printf("%d",sizeof(b));
getch();
}
Q(6)

void change(int const *p)
{
*((int *)p)=20;
}
void main()
{
int const x=10;
change(&x);
clrscr();
printf("%d",x);
getch();
}
solution:
(1)output:error modular division is only possible for integral data type
(2)output:4 2 2
(3)output:15 25
(4)output: 16
(5)output : 40
(6)output : 20

No comments:

Blog List