{
int d=5;
printf("%f",d);
}
ANS:
printf : floating point formats not linked
Abnormal program termination
2)void main()
{
int a=10, b=20;
printf(“%d %d”);
}
ANS:
20 10
3)void main()
float j;
j=1000*1000;
printf("%f",j);
}
ANS:
16960.000000
4)void main()
{
int count=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=∑
*temp=count;
printf("%d %d %d ",count,*temp,sum);
}
ANS:
20 20 20
5)void main (void)
{
int x;
x = 0;
if (x=0)
printf ("Value of x is 0");
else
printf ("Value of x is not 0");
}
ANS:
value of x is not 0
6)#include <stdio.h>
void main (void){
int mat [5][5],i,j;
int *p; p = &mat [0][0];
for (i=0;i<5;i++) for (j=0;j<5;j++)
mat[i][j] = i+j;
printf ("%d\t", sizeof(mat)); i=4;j=5;
printf( "%d", *(p+i+j));
}
ANS:
50 5
7)Number of files created when c program is compiled.
Ans: Varies from compiler to compiler.
Borland C compiler makes 2 files on first compile..
.obj and .exe
On further compiles if the code is changed a .bak file is created..
And GNU C compiler (cc/gcc) generates only a.out file (the executable file)
8)#include <stdio.h>
#define SQR(x) (x*x)
void main(void)
{
int a,b=3;
a = SQR (b+2);
printf("%d",a);
}
ANS:
11
9)#include <stdio.h>
void main (void)
{
int i = 0;
char ch = 'A';
do
putchar (ch);
while(i++ < 5 || ++ch <= 'F');
}
ANS:
AAAAAABCDEF
10)enum colors{RED,GREEN,BLUE}
main()
{
printf("%d,%d,%d",RED,GREEN,BLUE);
return 0;
}
ANS:
0,1,2
11)void main()
{
char *s="\12345s\n";
printf("%d",strlen(s));
}
ANS:
5
12)#define dprintf(expr) printf(#expr "=%d\n",expr)
main()
{
int x=7;
int y=3;
dprintf(x/y);
}
ANS:
x/y=2
13)void main(){
int i=0;
clrscr();
for(i=0;i<20;i++){
switch(i){
case 0:i+=5;
case 1:i+=2;
case 5:i+=5;
default: i+=4;
break;
}printf("%d,",i);
}}
ANS:
16,21,
14)main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}
ANS:
57 94
15)void main()
{
int i=6;
printf("%d %d %d %d %d ",i,++i,i++,++i,i++);
}
ANS:
10 10 8 8 6
16)void main()
{
printf("\n98");
printf("\b76");
printf("\r54");
}
ANS:
546
17)Which is illegal?
A)(((5)));
B)(((( ))));
C){{{ 5; }}};
D){{{{ }}}};
Ans B:
The choices that are legal have no effect. The compiler can choose not to generate code for them.
A. ((( 5 )));
This is a legal use of grouping parentheses around an expression.
B. (((( ))));
This is illegal because the grouping parentheses must group an expression.
C. {{{ 5; }}};
This is a valid use of curly braces to create compound statements. Each pair also creates a block.
D. {{{{ }}}};
This is a valid use of curly braces to create compound statements. Each pair also creates a block. The compound statement can have zero statements.
18)void main()
{
int i=400;
int *ptr=&i;
*++ptr=2;
printf("%d %d",i,*ptr);
getch();
}
ANS:
400 2
19)void main()
{
static int i;
while(i<=10)
(i>2 ? i++:i--);
printf("%d",i);
getch();
}
ANS:
32767
20)The Keyword used to transfer control
from a function back o the Calling function is :
ANS:
Return
21)Which of the following
cannot be checked in switch case statement?
a) Int
b) char
c) enum
d) float
ANS:
float
22)void main()
{
int i=10,j=20;
if(i=20)
printf(" Hello");
else
printf(" Hi");
}
ANS:
Hello
23)void main()
{
int i=3;
i=i++ + i++;
printf("%d",i);
}
ANS:
8
24)void main()
{
char str[]={"pvpit"};
char *s1=str;
s1++;
printf("%c",*s1);
}
ANS:
V
25)void main()
{
int i=5,j=6,k;
k=i&j;
printf("%d",k);
}
ANS:
4
26)void main()
{
int i=5,j=6;
printf("%d", i | j);
}
ANS:
7
27)size of Integer Data type on 32 bit Operating System is:
ANS:
4 Byte
28)range of unsigned char is
ANS:
0 to 255
29)What is the output of the following program?
void main()
{
int x=0,y=0;
if(x==0||++y)
printf(" x=%d",x);
printf(" y=%d",y);
}
Ans. X=0 y=0
In the controlling expression:
( x == 0 || ++y )
x == 0 evaluates to true, so the logical OR operation is short circuited and y is not incremented.
If && is used ++y is evaluated.
30)Which is NOT a statement?
a) int x;
b) ;
c) 4;
d) 0xF;
Ans:
int x;
is not a statement. This is a declaration.
//////////////////////////////////////////////////////////////////////////////////////////////////////
/*Bouncing ball simple*/
#include<graphics.h>
void main()
{
int gm,gd=DETECT,i,l=1,t=110,x=1,y=1;
initgraph(&gd,&gm,"");
while(!kbhit())
{
fillellipse(l,t,10,10);
delay(5);
if(l>=getmaxx()||l<=0)
{
x*=-1;
l=l<=0?0:getmaxx();
}
if(t>=getmaxy()||t<=0)
{
y*=-1;
t=t<=0?0:getmaxy();
}
l+=x;
t+=y;
cleardevice();
}
closegraph();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//Bouncing ball random
#include<graphics.h>
#include<stdlib.h>
void main()
{
int
gm,gd=DETECT,i,l=1,t=110,x=1,y=1,xr=random(3),yr=random(3);
initgraph(&gd,&gm,"");
while(!kbhit())
{
fillellipse(l,t,10,10);
delay(5);
if(l>=getmaxx()||l<=0)
{
x*=-1;
l=l<=0?0:getmaxx();
xr=random(3);yr=random(3);
}
if(t>=getmaxy()||t<=0)
{
y*=-1;
t=t<=0?0:getmaxy();
xr=random(3);yr=random(3);
}
l+=x+xr;
t+=y+yr;
cleardevice();
}
closegraph();
}
////////////////////////////////////////////////////////////////////////////
//bouncing ball with multiple balls.
#include<graphics.h>
#include<stdlib.h>
#define ANG 2
struct circl
{
int x,y,radius,l,t,xr,yr;
};
struct circl recalculate(struct circl cc)
{
if(cc.l>=getmaxx()||cc.l<=0)
{
cc.x*=-1;
cc.l=cc.l<=0?0:getmaxx();
cc.xr=random(ANG)+1;
cc.yr=random(ANG)+1;
}
if(cc.t>=getmaxy()||cc.t<=0)
{
cc.y*=-1;
cc.t=cc.t<=0?0:getmaxy();
cc.xr=random(ANG)+1;
cc.yr=random(ANG)+1;
}
cc.l+=(cc.x*cc.xr);
cc.t+=(cc.y*cc.yr);
return cc;
}
struct circl init()
{
struct circl
cc;
cc.l=getmaxx()/2;cc.t=random(500);cc.x=1;cc.y=1;cc.xr=5;cc.yr=10;
return cc;
}
void main()
{
int gm,gd=DETECT,i;
struct circl c[10];
initgraph(&gd,&gm,"");
for(i=0;i<=10;i++)
c[i]=init();
while(!kbhit())
{
for(i=0;i<=10;i++)
fillellipse(c[i].l,c[i].t,10,10);
delay(10);
for(i=0;i<=10;i++)
c[i]=recalculate(c[i]);
cleardevice();
}
closegraph();
}