Practice Questions: Predict the output of the following programs.
1.)main()
{
char a=3D 'A';
if(
(a=3D=3D'Z')||( (a=3D'L')&&( a=3D=3D'A')))
a=3Da;
printf("%c",a);=20
printf("
Nothing ");
}
2.)main()
{
static int a[5] ={2,4,6,8,10};
int i,b=5;
for(i=0; i< 5;i++)
{
f(a[i],&b);
printf("%d
%d\n",a[i],b);
}
}
f(x,y)
int x,*y;
{
x=*(y)+=2;
}
main()
{
printf("hello");
fork();
}
3. main()
{
char as[] = "\\0\0";
int i = 0;
do{
switch( as[i++]){
case '\\' :
printf("A");
break;
case 0 :
printf("B");
break;
default :
printf("C");
break;
}
}
while(i<3)
}
4. main()
{=20
int a;
a = (1,45,012);
printf("%d",
a);
}
5. main()
{
int i = 10;
printf(" %d
%d %d \n", ++i, i++, ++i);
}
6. #include<stdio.h>
main()
{
int *p, *c, i;
i = 5;
p = (int*)
(malloc(sizeof(i)));
printf("\n%d",*p);
*p = 10;
printf("\n%d
%d",i,*p);
c = (int*)
calloc(2);
printf("\n%d\n",*c);
}
7. #include<stdio.h>
main()
{
int arr[3][3] ={1,2,3,
4,5,6,
7,8,9};
int i,j;
for
(j=2;j>=0;j--){
for(i=2;i>=0;i--){
printf("\n%d",*(*(arr+i)+j));
printf("\n
TATATATA");
}
}
}
8. main()
{
int i = 5,
j=10;
abc(&i,&j);
printf("%d..%d",i,j);
}
abc(int *i, int
*j)
{
*i = *i + *j;
*j = *i - *j;
*i = *i - *j;
}
9. #define
PRINT(int) printf( "int = %d ", int)
main()
{
int
x=03,y=02,z=01;
PRINT (x | y
& ~z);
PRINT (x & y
&& z);
PRINT (x ^ y
& ~z);
}
10. main()
{
unsigned int m[]
= { 0x01,0x02, 0x04, 0x08,0x10, 0x20, 0x40, 0x80};
unsigned int n,i;
scanf("%d",&n);
for(i=0;i<=7;i++)
{ if (n&
m[i])
printf("\nyes");
else=20
printf("\nno");
}
}
11. main()
{
int a,b=2,c;
int *pointer;
c = 3;
pointer = &c;
a = c/*pointer;=20
b = c /*
assigning 3 to b*/;
printf("a
= %d; b = %d", a,b);
}
0 comments:
Post a Comment