C CODING CONTEST

Select the expected output of the below programs

Write the expected output for those questions not having choices.


1] 
#include<stdio.h>
 
void main( ){
 extern int i;
 i=20;
 printf(“%d”,sizeof(i));
 
}
 
a] 2 b] 4 c] Cannot be said d] None of the above
 
2]#include<stdio.h>
 
void main( )
 
{
 
int i=5.99999;
 
printf(“%d”,i);
 
}
 
a] 6 b] 5 c] Error cannot assign float to integer
 
d] None of the above

 

3]#include<stdio.h>
 
void main( )
 
{
 
display( );
 
}
 
void display( )
 
{
 
printf(“Cliffhangern”);
 
}
 
4]#include<stdio.h>
 
void main( )
 
{
 
union a
 
{
 
int i;
 
char ch[2];
 
};
 
union a u;
 
u.ch[0]=3;
 
u.ch[1]=2;
 
printf(“%d”,u.i);
 
}
 
a] 515 b] 770 c] 0 d] Error: u.i is uninitialized
 
5]#include<stdio.h>
 
void main( )
 
{
 
float a=0.7;
 
if(0.7>a)
 
printf(“Hi”);
 
else
 
printf(“Hello”);
 
}
 
a] Hi b] Hello c]Hi Hello d] None of the above
 
6]#include<stdio.h>
 
void main( )
 
{
int i=2;
int j=i+(1,2,3,4,5);
 
printf(“%d”, j);
 
}
 
a] 3 b] Error: j is undefined c]Error: Use of unknown operator
 
d] 7
 
7]#include<stdio.h>
 
void main( )
 
{
 
printf(“%d %d %d”,sizeof(3.14f),sizeof(3.14),sizeof(3.14l));
 
}
 
a]8 8 10 b]4 8 8 c]4 8 10 d]4 8 12
 
8]#include<stdio.h>
 
void main( )
 
{
 
/*This program attempts to find what happens when/*-32768 to +32768*/
 
is exceeded*/
 
int a =330000;
 
float b=3.4e100;
 
printf(“a=%d b=%fn”,a,b);
 
}
 
9]#include<stdio.h>
 
void main( )
 
{
 
printf(“%d”,4%3);
 
printf(“%d”,4%-3);
 
printf(“%d”,-4%3);
 
printf(“%d”,-4%-3); }
 
10]#include<stdio.h>
 
void main( )
 
{
 
int a=30,b=40,x;
 
x=(a!=10)&&(b=50);
 
printf(“x=%d”,x);
 
}
 
11]#include<stdio.h>

 
 
 
 
 
 
void main( )

{
 
int i;
 
printf(“Enter any number”);
 
scanf(“%d”,&i);
 
switch(i)
 
{
 
case 1:
 
printf(“do”);
 
case 2:
 
printf(“re”);
 
case 3:
 
printf(“me”);
 
case default:
 
printf(“fa so la ti do”);
 
}
 
}
 
12]#include<stdio.h>
 
void main( )
 
{
 
int area;
 
float radius=2.0;
 
area=areacircle(radius);
 
printf(“area= %f ”, area);
 
}
 
areacircle(r)
 
float r;
 
{
 
float a=3.14*r*r;
 
printf(“a=%fn”,a);
 
return(a);
 
}
 
13]#include<stdio.h>
 
void main( )
 
{
 
int a=33000;
 
float b=3.4e100;
 
printf(“%d %d”, sizeof(a),sizeof(b));
 
}

 
 
 
 
 
 
 
 
14]#include<stdio.h>
 
void main( )
 
{
 
int i=1;
 
if(!i)
 
printf(“recursive calls are painfuln”);
 
else
 
{
 
i=0;
 
printf(“recursive calls are challengingn”);
 
main( );
 
}
 
}
 
a] recursive calls are challenging
 
recursive calls are painful
 
b] recursive calls are painful
 
recursive calls are challenging
 
c] recursive calls are painful
 
d] recursive calls are challenging (infinitely.....)
 
15]#include<stdio.h>
 
void main( )
 
{
 
printf(“%d”,main( ));
 
}
 
a] prints garbage value infinitely
 
b] it runs an infinite loop without printing anything
 
c] compiler reports an error since main cannot be called recursively
 
d] address of main gets printed infinitely
 
16]#include<stdio.h>
 
int reverse(int);
 
void main( )
 
{
 
int no=5;
 
reverse(no);
 
}
 
reverse (int no)

 
 
 
 
 
 
{

if(no= =0)
 
return 0;
 
else
 
printf(“%d”,no);
 
reverse(no--);
 
}
 
a]program outputs values 5 4 3 2 1
 
b]program outputs values 1 2 3 4 5
 
c]program outputs values 5 4 3 2 1 0
 
d]program runs in an infinite loop
 
17]#include<stdio.h>
 
#define SWAP(a,b,c) (c t;t=a,a=b,b=t;)
 
void main( )
 
{
 
int x=10,y=20;
 
SWAP(x,y,int);
 
printf(“%d %d”,x,y);
 
}
 
18]#include<stdio.h>
 
#define MAX(a,b,c) (a>b?a>c?a:c:b>c?b:c) /* ? : has right to left
 
associativity */
 
void main( )
 
{
 
int x;
 
x= MAX(3+2,2+7,3+7);
 
printf(“%d”,x);
 
}
 
a] 5
 
b]9
 
c]10
 
d]3+7
 
19]#include<stdio.h>
 
void main( )
 
{
 
int i=3;

switch(i)
 
{
 
case 1:
 
printf(“au revoir”);
 
case 2:
 
printf(“adieu”);
 
break;
 
case 3:
 
continue;
 
default:
 
printf(“plain simple goodbye”); }}
 
20]#include<stdio.h>
 
void main( )
 
{
 
int b=20;
 
printf(“%d”,b);
 
{
 
int a=10;
 
printf(“%d”,a);
 
}
 
}
 
a] Error in declaration. All definitions must be at start of code.
 
b] Linker error:Undefined symbol a.
 
c] 20 10
 
d] None of the above

Leave a Reply

Your email address will not be published. Required fields are marked *

Enable Notifications OK No thanks