Results of C program

  • For division

20/7 = 2 7/20=0
20.0/7 =2.800000 7.0/20 =0
20/7.0 = 2.800000 7/20.0= 0
20.0/7.0 =2.800000 7.0/20.0=0

 

  • For percentage

20%7=6 -20%7=-6
20%-7=6 -20%-7=-6

 

  • main()

{

int a=b=c=d=20;

printf(“%d%d%d%d”,a,b,c,d);

}

Ans: Error

Explination: we cannot declare a=b=c=d=20

If d=20,c=d,b=c,a=b then ans will be 20,20,20,20

  • main()

{

Printf(“%%%%”);

}

Ans:%%, first and third % are the syntax

If it is 5 %%%%%  that is in odd number will give the answer as the error

  • main()

{

if(printf(“Hai”))

printf(“Face”);

else

printf(“Focus”);

}

Ans: HaiFace

Here Hai is of 3 characters so if(3) is valid condition so it is true then move to the Face to print.

  • Main()

{

Int a=1;

Switch(a);

{

Case1:printf(“one”);

Case2:printf(“two”);

Case3:printf(“three”);

default:printf(“invalid option”);

}

}

Ans: one two three invalidoption

Because there is no break statement so prints every printf statement.

  • Main()

{

Int i=10;

Printf(“%d%d”,++i,++i);

}

Ans:12,11

In the arthematic operation the associativity will be from right to left

So if we take right ++i then 10+1=11,and next ++I is 11+1=12. So it prints as 12,11

  • Main()

{

Int i=10,j=2,k=0,m;

M=++i||++j&&++k;

Printf(“%d%d%d%d”,I,j,k,m);

}

Ans:11,2,0,1

In logical operation the associativity from left to right

  • Main()

{

Int a=10,x=20;

a=a+++10;

x=x+++++a;

printf(“%d%d”,a,x);

}

Ans:22,43

a=11+10=21,x=21+22=43 here a=22 because in garbage it stores as 22 because of ++a

  • Main()

{

Int a=10,x;

X=a–+++a;

Printf(“%d”,x);

}

Ans:22

Here operation takes place from right to left. So from right pre increment there i.e, ++a=10+1=21,then post decrement a–= 21 then x=22, but in garbage the value of a changes to 10.

If in the program again if the another printf for a — printf(“%d”,a); then a=10 will be the answer.

  • Main()

{

Printf(“\n ks”);

Printf(“\b mi \a”);

Printf(“\r ha\n”);

}

Ans: hai

First, it takes ks as output then \b means backspace so cursor moves to k and s removes it then kmi is taken \r means carriage return so cursor moves at km and removes the km and places the ha.

  • Main()

{

Printf(“%d”,printf(“FACE”));

}

Ans:FACE4

First it prints FACE next FACE is of 4 characters so it takes as 4 and prints FACE4

  • Main()

{

Printf(“FACE”+2);

}

Ans: CE

Here FACE is considered as 4 characters so starts from 0,1,2,3 here +2 represents at the position 2 so from position 2 CE are present and it prints as CE

  • Main()

{

Int x,a=10;

X=a==10?printf(“hai\t”):printf(“hello\n”);

Printf(“%d”,x);

}

Ans: hai 4

Here terminay condition is present so 10==10 is valid so it prints hai and also 4 because hai is of 3 characters and \t is tab space one more character so totally 4 charaters.

  • Main()

{

Int a=10,b=20,c=5,d;

d=a<b<c;

printf(“%d”,d);

}

Ans:1

10<20 is true so it is taken as logic 1 and 1<5 is true so it is taken as logic one then it assigns 1 for d. so d=1.

Likes:
0 0
Views:
405
Article Tags:
Article Categories:
ACADEMICS

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.