You are on page 1of 18

1.#include <stdio.

h>
main()
{
int i;
i =0x10+010+10;
printf("%d",i);
}
ans : 34
----------------
2.main()
{
int x;
x = 4 % 5 + 6 % 5;
printf("x = %d",x);
}
ans : 5
---------------
3.main()
{
int i;
float j;
i =5/2;
j =5/2;
printf("%f %d ",j,i);
}
ans : 2.000, 2
--------------
4.main()
{
float a =12.25,b =13.25;
if(a = b)
printf("RISC");
else
printf("CISC");
}
ans : RISC
-------------
5.main()
{
int x =100;
if(!!x)
printf("x =%d",!x);
else
printf("x =%d",x);
}
ans : 0
-------------
6.main()
{
long i=65536 +65;
printf("%c\n",i);
char a;
printf("%d",a);
}
A
garbage.
---------------
7.main()
{
int q =2,d=3,st;
st = q*d/4-12/12+12/3*16/d;
printf("st =%d",st);
}
ans : 21
----------
8.main()
{
printf("%d %f\n",4,4);
printf("%d %f\n",4.0,4.0);
}
ans : 4 garbage
0 0
--------
9.#define MEAN(a,b,c,d,e) (a+b+c+d+e)/5
main()
{
int a,b,c,d,e,m;
a=1;b=2;c=3;d=4;e=5;
m = MEAN(a,b,c,d,e);
printf("Mean of the five numbers is =%d",m);
}
ans : 3
--------------
10. main()
{
printf("%d",1&2);
}
ans : 0
--------------
11.main()
{
int x;
x =3 * 4 % 5;
printf("x = %d",x);
}
ans : 12
--------------
12.main()
{
printf("%d %d %d %d ",72,072,0x72,0X72);
}
ans : 72 58 114 114
--------------
13. main()
{
printf("%d", 4||2);
}
ans : 1
--------------
14.main()
{
printf("%d",3||2);
}
ans : 1
-------------
15. main()
{
printf("%d",3&&2);
}
ans : 1
--------------
16. main()
{
int g = 300 * 300 /3;
printf("g =%d",g);
}
ans : 8154
--------------
17.main()
{
printf("%d",3>2);
}
ans : 1
--------------
18.main()
{
float x = 5.5,y=8.0;
x*= ++x;/*for float there is no effect in using post ++*/
y++;
printf("%f %f",x,y);
}
ans 15.75 9
-----------------
19.main()
{
int x=2,y,z,s;
x*= y=z=4;
s=(y==z);
printf("%d\n",x);
printf("%d",s);
}
ans : 8
1
----------------
20. main()
{
int x,y,z;
x=2;y=1;z=0;
x=(x&&y)||z;
printf("%d\n",x);
printf("%d\n",x||y&&z);
x=y=1;
z=x++ -1;
printf("%d\n",x);
printf("%d\n",z);
z+= x++ + ++y;
printf("%d\n%d\n",x,z);
}
ans : 1
1
2
0
3
4
-----------------
21. main()
{
int x = 0,z,y;
z = !x|x;
y = x|!x;
printf("%d %d",z,y);
}
ans : 1 1
--------------
22.#include <stdio.h>
main()
{
int i=100,j=200;
printf("%d %d");
}
ans : 100 200
---------------
23.main()
{
int x = 2,z;
for(x=2;x<=10;x++)
{
printf("%d\t",x);
printf("%d\n",~x);
}
x=2;
z = ~(x|x);
printf("%d",z);
}
ans : 2 -3
3 -4
...
10 -11
-3
-----------------
24. main()
{
int x=1,y=1,z=1,aa;
x+=y+=z;
printf("%d %d %d\n",x,y,z);
aa = x<y?x++:y++;
printf("%d",aa);
}
ans : 3,2,1,2
----------------
25. main()
{
int x=-1,y=-1,z=-1,a;
a=(x++ && y++) || ++z;
printf("%d %d %d %d", x,y,z,a);
}
ans :0,0,-1,1
----------------
26. main()
{
int y=100,x;
x = y= y++;
printf("%d %d ", x,y);
}
ans : 100, 101
----------------
27.#include<stdio.h>
main()
{
int x,y=1,z;
if (z=(y==1)) x=5;
else x=10;
printf("x=%d\t y = %d\t z=%d ",x,y,z);
}
ans:5 1 1
----------------
28. # include<stdio.h>
main()
{ int x,y=1,z;
if (z=y<0) x=3;
else
if (y==0) x=5;
else x=7;
printf ("%d %d %d",x,y,z);
}
ans : 7 1 0
------------------
29. #include<stdio.h>
int i=0;
main()
{
auto int i=1;
printf("%d\n",i);
{
int i=2;
printf("%d\n",i);
{
i+=1;
printf("%d\n",i);
}
printf("%d\n",i);
}
printf("%d\n",i);
}
ans : 1 2 3 3 1
-------------------
30. # include<stdio.h>
main()
{
int a=6;
a+= a++ + ++a;
printf("%d",a);}
ans : 22
------------------
31. main()
{
static char food[]="yummy";
char *ptr;
ptr=food + strlen(food);
while (--ptr>=food)
puts(ptr);
}
ans : y
my
mmy
ummy
yummy
--------------------
32. main()
{
int i =10;
#include<stdio.h>
printf("%d",i);
}
ans : 10
-------------------
33. # define FUN(k) a+b/*d-bc*/c
main()
{
int a,b,c,*d,bc;
a=6;b=5;c=4;bc=2;
d=&c;
printf("%d\n",FUN(K));
}
ans : 8
-------------------
34.main()
{
int x,a,b,c;
a=10;b=5;c=5;
x=a==b + c++;
printf("%d",x);
}
ans : 1
-------------------
35.include<stdio.h>
main()
{
int *a=71;
printf("%d %d",a,*a);
}
ans : 71, garbage /*my comment : error in Unix. Core will be
dumped*/
--------------------
36. # include<stdio.h>
main()
{
static int arr[]={ 97 ,98 ,99 ,100 ,101 ,102 ,103 ,104 };
int *ptr = arr+1;
print(++ptr,ptr--,ptr,ptr++,++ptr);
}
print(int *a,int *b,int *c,int *d,int *e)
{
printf("\n%d %d %d %d %d",*a,*b,*c,*d,*e);
}
ans : 100 100 100 99 99
---------------------
37.#include <stdio.h>
main()
{
int i;
int a[] = {1,2,3,4,5,6,7};
for(i=0;i<=4;i++)
{
printf(" %d ",a[i]);
}
}
ans : 1 2 3 4 5
-----------------
38.main()
{
int a,i;
i = 11;
a = i++ + ++i + --i;
printf("%d %d",a,i);
}
ans:33 12
-----------------------
39.main()
{
int i=10;
printf("\n value of i =%d address of i =%u",i,&i);
&i==7200;
printf("\nnew value of i=%d new address of i =%u",i,&i);
}
ans : no change
------------------------
40.main()
{
int *i,*j,**k;
j=i+2;
k =&i;
printf("\nk=%u j=%u i=%u",*k,j,i);
}
ans : addr pnted by i, addr pnted + 4, addr in i
--------------------
41. #include <stdio.h>
main()
{ union{
struct cathy{
int cathy;
char joe;
}cat;
int m;
}ass;
printf("\nsize of :%d " ,sizeof(ass));
}
ans : 3
-----------------
42.#include<stdio.h>
main()
{
int i=3,j;
j= i++ * ++i * ++i;
printf("%d %d",j,i);
}
ans : 125 6
---------------
43. main()
{
int aa0aa1aa2aa3aa4aa5aa6aa7aa8aa9aazz1zz2 =10;
printf("%d",aa0aa1aa2aa3aa4aa5aa6aa7aa8aa9aa);
}
ans : 10 (Compiler dependent)
-----------------
44.#include<stdio.h>
main()
{
char in;
while ((in = getchar())!= '*')
{
if ((in >= 'a') && (in <='z'))
another();
}
}
another()
{
static int i=0;
i++;
printf("%d",i);
}
ans : if abc* is given as input then output is 123
---------------
45. #include<stdio.h>
main()
{
int stud[5][2]={
{1234,56},
{1212,33},
{1434,80},
{1312,78},
{1203,75}
};
int i,j;
for(i=0;i<=4;i++)
{
printf("\n");
for(j=0;j<=1;j++)
printf("%d",*(*(stud+i)+j));
}
}
ans: 123456
121233
143480
..
---------------
46. # include <stdio.h>
# define BYTESIZE
main()
{
int printbits(int);
int x =5;
printbits(~x);
}
printbits(x)
int x;
{
int i;
for(i=0;i<BYTESIZE*sizeof(x);++i)
printf("%d",(val <<i&1<<BYTESIZE*sizeof(int)-1)?1:0);
putchar('\n');
}
ans : error.
------------------
47. #include <stdio.h>
main()
{
int i=12,j=3,k =2;
/* 1 + 1 = 0 & 1+0 | 0+1 = 1 for XOR */
/* prece => compli ,AND,OR,XOR */
printf("%d ",i^j&~k);
printf("%d %d",i & j,i & j && k);
}
ans : 13 0 0
-------------
48. main()
{
/* !x gives 0 for +ive & -ive values ;one for 0 */
int x = 2;
printf("!x = %d\n",!x);
printf("%d\n",!x|x);
printf("%u\n",~x|x);
printf("%u\n",x<<1);
printf("%u\n ",x>>1);

}
ans : 0
2
65535 (Depends on the machine)
4
1
-----------------
49.#include<stdio.h>
main()
{
int a,b,c;e
a = b =c= -1;
++a || ++b && ++c ;
printf("a = %d ,b = %d , c = %d",a,b,c);

}
ans : 0 0 -1
-------------
50.#include<stdio.h>
main()
{
int a,b,c;
a = b = -2;
c = ++a && ++b ;
printf("a = %d ,b = %d , c = %d",a,b,c);
}
ans : -1 -1 1
--------------
51.#include<stdio.h>
main()
{
int x,y,z;
x = y = 0;
while(y <10)
{
x += ++y;
printf("%d %d\n",x,y);
}
}
ans : 1 1
3 2
6 3
10 4
15 5
21 6
28 7
36 8
45 9
55 10
--------------
52.main()
{
int x=1,y=1;
if (y<0)
if (y>0) x=3;
else x=5;
printf("%d",x);
}
ans : 1
---------------
53.#include<stdio.h>
main()
{
int c,nd =0,no =0;
while((c =getchar())!= '\n')
switch(c) {
case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
case '9' :

nd++;
default:
no++;
break;
}
printf("%d %d ",nd,no);
}
ans : when input is 123abc<enter> , nd=3 no = 6
-------------------
54.main()
{
int x,y=1,z;
if (x=y=z);x=3;
printf("%d %d",x,z);
}
ans : x=3 z=garbage
----------------
55.main()
{
int a,b;
a =-3 - -3;
b =-3 - -(-3);
printf("a = %d b =%d",a,b);
}
ans : a=0 b=-6
----------------
56.#include<stdio.h>
main()
{
long count;
count = 62000+1536+10;
printf("%ld ",count);
}e
ans : 63546
----------------
57.main()
{
long i;
i =65536+300;
printf("%ld ",i);
}
ans : 65836
---------------
58.main()
{
int *a;
*a = 1;
printf("%d %d",a,*a);
}
ans : garbage, 1
-----------------
59.#include <stdio.h>
int a[][2] ={1,2,3,4};
main() {
int i,j;
int (*p)[2]=a;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
printf("%u \t\t%u \n",*p+j,*(*p+j));
p++;
}
}
ans :
158 1
160 2
162 3
164 4
---------------
60.main()
{
int *a=1;
printf("%d %d",a,*a);
}
ans : 1, garbage
---------------
61.main()
{
char a[]={"jeban"};

printf("%*s",(40+strlen(a)),a);
}
ans : 45 spaces + jeban
----------
62.#include <stdio.h>
void cube(int *,int *,int *);
main()
{
int x=5,y,z;
cube(&x,&y,&z);
printf("value of x =%d",x);
printf("\nIts cube =%d",z);
}
void cube(int *a,int *b,int *c)
{
*b = (*a)*(*a);
*c = (*b)*(*a);
}
ans: x=5 z=125
----------------
63.main()
{
int i=2,j=3,k;
k=i+++j;
printf("%d %d %d",i,j,k);
}
ans : 3 3 5
-----------
64.compute(int m,int n)
{
if(m==0)
return(n+1);
else
{
if(n==0)
compute(m-1,1);
else
compute(m,compute(m-1,n));
}
}

main()
{
int i;
i = compute(2,3);
printf("%d",i);
}
ans : bull shitting question
------------------
65.main()
{
int i=0;
char *cat ="city\0ki0ng";
while(*cat++)
{
i++;
printf("%d\n",i);
}
}
ans : 1 2 3 4
------------------
66.#include <stdio.h>
int i;
main()
{
char joe[10] = "city\0ki0ng";
char ch;
for(i=0;(ch=joe[i]!=0);i++)
{
ch=ch+'a'-'A';
printf("%d\n",ch);
}
}
ans : 33
33
33
..
--------------
67.#include <stdio.h>
main()
{
FILE *fp;
char str[20];
fp = fopen("new.out","w");
if(fp == 0)
printf("File opening error");
else
{
printf("Enter your name:");
scanf("%s",str);
fprintf(fp,"%s",str);
fclose(fp);
}
}
ans : too simple
----------------
68.#include <stdio.h>
main()
{
FILE *fp;
char a;
fp = fopen("old.out","w");
if(fp == 0)
printf("File opening error");
else
{
for(scanf("%c",&a);a!=EOF;scanf("%c",&a))
fprintf(fp,"%c",a);
fclose(fp);
}
}
ans : same as the previous one
-------------------
69.main()
{
int a=(10,15,12,77);
printf("%d ",a);
}
ans : 77
-----------------
70.main()
{
char a;
printf("%d",(2^3)+(a^a));
}
ans: 1
-----------------
71.main()
{
int i = 5;
printf("%d",i);

return(991211233232132323232242243333322232344233232323232342342242422
printf("hai");
}
ans : 5
-----------------
72.main()
{
int i=4,*j,*k;

j=&i;
printf("\n%d\n",j);
j=j+1;
printf("\n%d\n",j);
j=j+9;
k=j+3;
printf("%d %d %d ",i ,j ,k);
}
ans : too simple
--------------
73.#include<stdio.h>
#include<conio.h>
#define CL printf("%c%c%c%c",27,91,50,74)
#define MC(x,y) printf("%c%c%d%c%d%c",27,91,x,59,y,72)
#define VR printf("%c%c%c%c",27,91,55,109)
#define VB printf("%c%c%c%c",27,91,53,109)
#define VO printf("%c%c%c%c",27,91,53,109)
main()
{
CL;
MC(12,33);
printf("hai");
VR; /*macro for reverse video on */
printf("\nhallo");
VO; /*macro for reverse video off */
printf("\nbye" );
MC(17,25);
VB; /* macro for video blink */
printf("\nHELLO");
}
ans : prints some bull shit
---------------
74.main()
{
printf("%d",0.3.);
}
ans : error.
----------------
75.main()
{
int a=3,b=2;
if (a=b)
printf("The two numbers are same");
else
printf("The two numbers are not same");
}
ans : two numbers are same
---------------
76. #include <stdio.h>
main()
{
char *s="abc";
char *t;
for (t=s;*t!='\0';++t)
{ switch (*t)
{
case 'a':
putchar('1');
case 'b':
putchar('2');
case 'c':
putchar('3');
break;
}
}
putchar('\n');
}
ans : 123233
-------------------
77.#include <stdio.h>
main()
{
struct word
{
char *string;
int length;
};
struct word dict[2];
struct word *p =dict;

p->string = "structure";p->length =9;


(++p)->string ="word";p->length= 5;
printf("%d\n",(--p)->length);
printf("%c",*(p->string));
}

ans : 9 s
------------------------
78.#include <stdio.h>
char *strchr(char *s,char c)
{
while(*s++!= c);
return s;
}

main()
{
char str[30];
gets(str);
puts(strchr(str,'a'));
}
ans : input given "juggernauts"; output is uts
----------------
79.#include <stdio.h>
void main(void)
{
int i=5;
printf("\n%d",i);
change(i/2);
printf("\n%d",i);
i=change(i/2);
printf("\n%d",i);
}

int change(int i)
{
return i<=5 ? 2 : 5 ;
}
ans : 5 5 2
-------------
80. #include <stdio.h>
main()
{
printf("%d",func());
}

int func()
{
_AX=100;
}
ans : 100
-------
81.#include <stdio.h>
char *mycopy(str)
char *str;
{
char ptr[20];
strcpy(ptr,str);
return(ptr);
}
main()
{
char name[20];
char parm[20];

strcpy(name,"malini");
parm =mycopy(name);
puts(parm);
}
ans : error
---------------
82.# include<stdio.h>
# include<ctype.h>
main()
{
char a;
a = getchar();
if isupper(a)
printf("entered value is upper");
else
printf("entered value is lower");
}
ans : input 'a'. output: entered value is lower
--------------
83.main ()
{
int a = 10,b=5;
a ^=b^=a^=b;
printf("%d %d ",a,b);
}
ans : 5 10
----------------
84.main()
{
float a=0.131200;
printf("%d ",a);
}
ans : 0
------------------
85.#include <stdio.h>
main()
{
int *i,j;
i =&j;
i =i+ 5;
printf("%d %d",i,&j);
}
ans : (compiler dependent) &j+10, &j
----------------------
86.main()
{
char a[10],*pc;
int j;
pc = a;
pc =pc + sizeof(a);
j=pc-a;
printf("%d",j);
}
ans : 10
-------------------------------------------

You might also like