You are on page 1of 6

CSEA WEEK

C Contest (Expert Level)


Time Limit – 20 Minutes
1. What will be the output of the following program?
#include<stdio.h>
enum Bool {FALSE=0, TRUE} Boolean;
#define FALSE 1
int main()
{
enum Bool Boolean;
printf("False value %d\n", FALSE);
printf("True value %d\n", TRUE);
return 0;
}

a. Compiler error
b. False value 0
True value 1
c. False value 0
True value 0
d. False value 1
True value 1

2. What will be the output of the following program?


#include<stdio.h>
int main()
{
struct test
{
char name[]="hello";
};
struct test *s;
printf("%s",s->name);
return 0;
}

a. Compiler error
b. hello followed by junk characters
c. hello
d. h

3. How to declare a function pointer that returns void and takes the following two parameters?
1) an integer variable
2) a pointer to function that returns void

a. void (*func( int, *f () ) ) ();


b. void (*func( int, void ( *f) () ) ) ();
c. void (*func( int, (*f) () ) ) ();
d. void (func *( int, void *(f) () ) ) ();
4. What will be the output of the following C code?
#include<stdio.h>
int i;
int func(int *x)
{
static int y=2;
if( y=y|4)
{
y++;
}
return y;
}

void main()
{
printf("%d, %d",func(&i),i);
}

a. 7, 7
b. 7, 0
c. Garbage Value
d. 4, 4

5. The following notation of defining functions is known as __________


int abc(a,b)
int a; float b;
{
/* some code*/
}

a. ANSI C notation
b. Kernighan & Ritche notation
c. CamelCase notation
d. None of these

6. What will be the output of the following program?


#include<stdio.h>
int main()
{
char a[5][5],flag;
a[0][0]='A';
flag=((a==*a)&&(*a==a[0]));
printf("%d\n",flag);
return 0;
}

a. Runtime error
b. 1
c. 0
d. Compiler error
7. What will be the output of the following program?
void main()
{
int i=12;
printf("%d\n",printf("%d",printf("%d",i)));
}

a. 1234
b. 1221
c. 12
d. Compiler error

8. What will be the output of the following program?


void main()
{
int i=1;
switch(i)
{
lab:
case 0:
printf("%d", i);
break;
case 1:
++i;
printf("%d", i);
goto lab;
}
}

a. 12
b. Compiler error
c. 22
d. 21

9. What will be the output of the following program?


#include<stdio.h>
void f1(){printf("func1");}
void f2(){printf("func2");}
void f3(){printf("func3");}
static int (*fPtr[3])();

void sFunc(int *ptr[], void (*f)(void),int index)


{
ptr[index]=f;
}
int main()
{
int i=0;sFunc(fPtr,f1,0);
sFunc(fPtr,f2,1);
sFunc(fPtr,f3,2);
fPtr[2]();
return 0;
}
a. Runtime error
b. func3 func2
c. func3
d. func2
10. What will be the output of the following program?
#include<stdio.h>
int main()
{
static int i;
int temp;
for(i;i<16;i++)
{
temp = (1<<i)&i;
printf("%d",temp);
}
return 0;
}

a. It will print the binary representation of 16


b. Garbage
c. It will print 16 0’s
d. None of these

11. What will be the output of the following program?


void main()
{
int India[ ]={2.8,3.4,4,6.7,5};
int germany,*p=India,*q=India;
for(germany=0;germany<5;germany++)
{
printf(" %d ",*India);
++q;
}
for(germany=0;germany<5;germany++)
{
printf(" %d ",*p);
++p;
}
}

a. Runtime error
b. 2 2 2 2 2 2 3 4 6 6
c. 2 2 2 2 2 2 3 4 6 5
d. Compiler error

12. What will be the output of the following program?


#include<stdio.h>
int i = 0;
int main()
{
static i=3;
printf("%d ",i--);
return i>0 ? main():0;
return 0;
}

a. Redefinition error
b. 3 3 3
c. 3 2 1 0
d. 3 2 1
13. What will be the output of the following program?
#include<stdio.h>
int main()
{
int a[][3] = { 1,2,3 ,4,5,6};
int (*ptr)[3] =a;
printf("%d %d ",(*ptr)[1],(*ptr)[2]);
++ptr;
printf("%d %d ",(*ptr)[1],(*ptr)[2]);
return 0;
}

a. 1 2 4 5
b. Compiler error
c. 5 6 0 0
d. 2 3 5 6

14. What will be the output of the following program if MyFile.txt contains Clue[EOF]Less[\n][space]Life[\n]?
#include<stdio.h>
int main()
{
char buff[80];
FILE* fp=fopen("MyFile.txt", "w");
if(!fgets(buff, 80, fp))
return 1;
printf("buff= %s\n", buff);
return 0;
}

a. Clue
b. Clue[EOF]Less[\n][space]Life[\n]
c. buff will be empty
d. Program will crash

15. What will be the output of the following program?


#include<stdio.h>
int main( )
{
printf ( 5 + "Good Morning" ) ;
return 0;
}

a. Good Morning
b. Morning
c. M
d. Good
16. Consider following program. Assume that source file contains a statement “To err is human”.
#include <stdio.h>
int main( )
{
int i, fss ;
char ch, source[20] = "source.txt", target[20] = "target.txt", t ;
FILE *fs, *ft ;
fs = fopen ( source, "r" ) ;
ft = fopen ( target, "w" ) ;
while ( 1 )
{
ch = getc ( fs ) ;
if ( ch == EOF )
break ;
else
{
fseek ( fs, 4L, SEEK_CUR ) ;
fputc ( ch, ft ) ;
}
}
return 0;
}
What would be the contents of target.txt file?

a. r n
b. Trh
c. Err
d. None of these

17. What will be the output of the following program?


#include<stdio.h>
int main()
{
int **ptr;
static int a[]={0,1,2,3,4};
static int *p[]={a,a+1,a+2,a+3,a+4};
ptr=p;
printf("\n%d %d %d",ptr-p,*ptr-a,**ptr);
*++*ptr;
printf("\n%d %d %d",ptr-p,*ptr-a,**ptr);
return 0;
}

a. 1 2 3
223
b. 1 0 1
102
c. 0 0 0
011
d. 0 1 1
111

You might also like