C Programming
C Programming
C Programming
Basics of C
Q. 1 void main( )
{ printf(“%d”, sizeof(char));
printf(“%d”, sizeof(int));
printf(“%d”, sizeof(float));
}
a. 1 2 4 b. 1 4 4 c. Error : invalid parameter to sizeof d. 2 4 4
Q. 4
void main( )
{
printf(“%d”, printf(“*usm*”) );
}
a. Error b. *usm*5 c. *usm* d. 5*usm*
1
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
Q.7 'C' Language is developed by _________.
a. Stroustrup b. Kernighan Ritche c. Ken Thompson d. Dennis Ritchie
Q.10
C' is a ________level language.
a. lower b. high c. mid Feedback
Q.17 Which of the following statements are true regarding arithmetic operators?
i) An arithmetic operation between an integer and an integer yields an integer
ii) An arithmetic operation between two floats yields an integer
iii) An arithmetic operation between an integer and a float yields an integer
iv) An arithmetic operation between an integer and a float yields a float
a. i and iv b. i and iii c. ii and iii d. ii and iv
Q. 20
2
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
void main( )
{
printf(“%c”, „%d‟ );
}
a. garbage b. d c. %c d. Error
Q.21
void main( )
{ char ch='12';
printf(“%d”, ch );
}
a. 1 b. 50 c. 12 d. Error
Q.29
void main( )
{
printf(“\\\65” );
}
a. \5 b. \\65 c. \A d. \65
3
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
a. gets char from user & shows it on screen
b. gets char from user & does not show on screen
c. gets char from file
d. shows output to user
Q.32 By default how many decimal places are displayed for %f used for float variable?
a. 6 b. depends on data c. 2 d. 0
Q.34
void main( )
{
printf(“%d %d %d”, 8 );
}
a. Error b. 8 8 garbage c. 8 0 0 d. 8 0 garbage
Q.35
int x = 10;
void main( )
{printf(“%d”,x);
{int x =20;
{ int x =30;
printf(“%d”,x);
}
printf(“%d”,x);
}
}
a. Erro b. 10 30 30 c. 10 30 20 d. 10 20 30
Q.37
void main( )
{
printf(“Today\r\bis a\7 great\t\r\\day”);
}
Select one:
a. day 7 great b. Todayrbis a\7 greattrday c. is a 7 great day d. \day great
Q.38
void main( )
{int ch=26;
printf(“%X”, ch );
}
4
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
a. 1a b. 1 A c. 26 Feedback
Expression
Q. 1
void main( )
{ int a=2, b, c,d;
b=c=5;
d=++a- --b*c%b;
printf(“d”, d);
}
a. 3 b. 2 c. -1 d. Error:Lvalue required
Q. 2
void main( )
{ float a=5,b=2;
printf(“%f”, a%b*2);
}
a. 2.0 b. 0.5 c. error d. 1.0
Q.3
void main( )
{ int u1; float u2;
printf(“%d”, sizeof(u2+sizeof(u1)));
}
a. 4 b. 8 c. C d. 6
Q.4
void main( )
{ int i=20, j=30;
i^=j;
j^=i;
i^=j;
printf(“%d, %d”, i, j);
}
a. 0,0 b. 30,20 c. 20,30 d. 20,20
Q.5
void main( )
{ int x=32767, y=9;
x=x+y;
printf(“%d”, x);
}
5
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
a. Garbage value b. 32776 c. -32760 d. -32776
Q.6
void main( )
{ int p=4;
printf(“%d”, ++p*p++*++p);
}
a. 216 b. none c. 175 Feedback
Q. 12
void main( )
{ int x=1, y=2, z=6;
x+=x+y*z=8;
printf(“ %d”, x);
}
a. Compi b. 18 c. 14 d. 2
Q.13
void main( )
{ char ch=-3;
printf(“%d %d %d”, -ch, -ch+1, !ch );
}
a. 3 132 0 b. -3 132 1 c. 3 -3 1 d. 3 4 0
Question 14
void main( )
{ int a=5, b=2;
printf(“%d %f %f”, a/b, (float)a/b, a/(float)b );
}
a. 2 2.5 2.5 b. 2 2.500000 2.500000 c. 2 2.000000 2.500000
6
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
Question 15
void main( )
{ char b='C ', c='B';
printf(“%c”, c+b-36);
}
a. A b. a c. 133
Q.16 Which unary operator changes operand?
a. ~ b. ! c. - - d. -
Q.17
void main( )
{ int no 1 =0;
printf(“%d”, 5/no 1);
}
a. Compilation error b. 32767 c. 5 d. None of them
Q.18
void main( )
{ int p=5, x;
x=++p*p++;
printf(“%d”, x);
}
a. 36 b. 49 c. 42 d. 30
Q.19
void main( )
{ int xx=3*(5 +1)/(2-2*10);
printf(“%d”, xx);
}
a. -1 b. None of them c. 1 d. 0
Q. 20
void main( )
{ int i=1, j=0, k=i--&&++j||--i;
printf(“%d %d %d”, i, j, k);
}
a. 0 1 0 b. None of these c. 1 1 1 d. 0 1 1
Q.22
void main( )
{ int i=2, j=3, k=0, m=0 ;
float a=1, b=2;
k=i/j *k;
7
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
m=j/i*j;
a=i*/j*j;
b=i*j/k;
printf(“%d %d %f %f ”, k, m, a, b);
}
a. 0 3 0.000000 0.000000
b. Error
c. 0 3 0.000000 2.000000
d. 2 3 0.000000 2.000000
Q.23
void main( )
{ int x=1, y=2, z=3;
printf(“ %d %d %d”, ++x, x+y, z);
}
Select one:
a. 2 4 3 b. c. 1 3 3 d. 2 3 3
Q.25
void main( )
{ int s1 = 1, s2=4;
printf(“%d”, (s1&s2)?5:10 );
}
a. 5 b. 10 c. 0 d. 1
Q. 27
void main( )
{ int p=10;
printf(“%d %d %d”, --p, --p, --p);
}
a. 9 8 7 b. 7 8 9 c. 10 9 8 d. 7 7 7
Q.29
void main( )
{ int p=1, q=2, r=3;
float p=1.0, q=2.0, r=3.0;
8
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
printf(“%d %d %f”, p, q, r);
}
a. error b. 1 2 3 c. 1 2 3.0 d. 1.0 2.0 3.0
Q.30
void main( )
{ int x=2;
float f1=1.0, f2=2.0, sum;
sum=x*f1+f2/x+f1*f2;
printf(“%f ”, sum);
}
a. Compilation error b. 1.500000 c. 6.000000 d. 5.000000
Q.35
void main( )
{
printf(“%d”, 32>>2 );
}
a. 30 b. 128 c. 8
Q.39
void main( )
{ int v=-5, w=0, x=4;
9
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
printf(“%d”, w || v || x&&w);
}
a. 1 b. 5 c. Garbage value is printed d. 0
Q.40
void main( )
{ int product;
char ch='CH';
product(“%d”, product);
}
a. 99 b. 67 c. Garbage d. Error:Character constant too long
Q.41
void main( )
{ char ch=20;
printf(“%d %d”, ch>>4, ch <<2 );
}
a. 180 10 b. 1 80 c. 5 40
Q.43
void main( )
{ int p=10;
printf(“%d %d %d”, p--, ++p, p--); // 10 10 10
-1 9 -1
}
a. 9 11 10 b. 10 9 10 c. 10 10 10 d. error
Q.44 Which operator does not check 2nd condition if 1st condition is false?
a. & b. || c. && d. >>
Q.46
void main( )
{ char c1='1', c2='2'; 73+50
int sum=c1+c2;
printf(“%c %d”, sum, sum);
}
a. c 99 b. 3 garbage c. C 99 d. sign 123
Q.47
void main( )
{
10
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
printf(“%d”, 5/0 );
}
a. 32767 b. Runtime error c. Compilation error d. 5
11
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
b. default must be last case in switch
c. default must be first case in switch
d. default is compulsory in switch
Q.17 Which character is used in switch to separate case from its action part
a. blank b. : c. ; d. ,
Q.19
void main( )
12
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
}
a. 15 b. 10 c. 16 d. 11
Q.20
void main( )
{ float f=5.4;
if(f= =5.4) printf(“equal”);
else printf(“not equal”);
printf(“%f”, f);
}
a. equal b. not equal 5.400000 c. not equal d. 5.400000
Q.21
void main( )
{ int a=2, b=3;
if(a=b); printf(“equal”);
else printf(“not equal”);
}
a. not equal b. equal c. No output d. Error
Q.22
void main( )
{ if( ! 123.4 ) printf(“WELCOME”);
Else printf(“GET OUT”);
}
a. WELCOME b. GET OUT c. no output d. Error: improper if condition
Q.23
void main( )
{ static int i;
if(!(i=1)) printf(“USM”);
else printf(“usm”);
}
a. usm
b. USM
c. Error:static variable not allowed in C
d. Error: invalid if condition
Q.24
void main( )
{ int a=2,b=3;
if(a>b);
printf(“*”);
printf(“+”);
}
13
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
a. * b. + c. *+ d. no output
Q.25
void main( )
{ int a=2,b=5,c=1;
if(a>b)
if(a>c) printf(“*”);
else printf(“*”);
printf(“+”);
}
a. *+ b. **+ c. *** d. +
Q.26
void main( )
{ int a=3,b=0;
if(a,b) printf(“*”);
else printf(“+”);
}
a. * b. + c. *+ d. Error
Q.27
void main( )
{ int k=1,b=0,c=++b;
else printf(“+”);
print(“%d”, k);
}
a. *0 b. +0 c. *1 d. +1
Q.28
. void main( )
{ int a=0,b=1;
}
a. 0 1 b. 0 0 c. -1 0 d. 1 1
Q. 29
14
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
void main( )
{ int a=3,b=1;
}
a. 3 b. 1 c. 0 d. Error
Q. 30
void main( )
{ int a=0,b=2;
}
a. 0 1 b. 2 1 c. 1 0 d. Error
Q.31
if(a>b) b=a;
if(c>b) b=c;
printf(“%d”, b);
What is represented by above code?
a. it prints value of b as it is b. it prints minimum of 3 nos. a, b, c
c. it prints maximum of 3 nos. a, b, c d. it prints average of 3 nos. a, b, c
Q.32
void main( )
{
int m=0,n=5/2+3*6;
if( !m++ && ++m) printf(“%d”, m++);
else printf(“%d”, m--);
}
Select one:
a. 1 b. 2 c. 3 d. 0
Q.33
void main( )
{
int m=3, n=4;
if(m&n) printf(“%d”, m--);
15
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
else printf(“%d”, n++);
}
a. 3 b. 4 c. 2 d. 5
Q.34
void main( )
{
int m=0, n=-1;
if(~m && ~n) printf(“%d”, n);
else printf(“+%d”, ~m);
}
a. +-1 b. -1 c. +32767 d. 32768
Q. 35
void main( )
{
char a='A';
else a='c';
printf(“%c”, a);
}
a. a b. b c. c d. Error
Q.36
void main( )
{ char a='A';
else a='c';
printf(“%c”, a);
}
a. a b. c c. A d. Error
Q.37
void main( )
{ char a='A';
16
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
else a= ='C'+' ';
printf(“%c”, a);
}
a. a b. c c. A d. Error
Q.38
void main( )
{ int a=2,b=3;
if(a<=b)
if(a=b) printf(“**”);;
else printf(“****”);
}
a. ** b. **** c. No output
Q.39
void main( )
{ float j=0.1;
switch( j )
default : printf(“Default”);
}
a. 0.1 b. 0.1 0.2 c. 0.1 Default d. Error
Q. 40
void main( )
{char c='a';
17
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
{ case 'a': ++c; goto lable;
}
a. b b. c c. b c d. a b c
Loops
Q.1 What is not a difference between while & do-while loop?
a. In while loop condition is checked 1st & in do while it is checked last
b. do-while loop executes at least once whereas while loop may not execute in worst case
c. while loop stops when condition is false whereas do-while stops when condition is true
d. In while loop, condition decides execution of current iteration whereas in do while, it decides execution of
next iteration.
Q.3
void main( )
{ int i=0;
for(;i=2;) { printf(“%d ”, i); i++; }
}
a. 0 b. 0 1 2 c. 0 1 d. Infinite loop
Q. 5
void main( )
{ char ch='\0';
while(ch)
{ printf(“ end of output is %c”, ch);
break;
}
printf(“ null character”);
}
a. null character b. end of output is 0 null character
c. end of output is \0 null character d. end of output is null character
Q.6
void main( )
{ int i=0;
18
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
for(;i<=5;) printf(“%d ”, i=i*2);
}
a. 0 2 4 b. 0 1 2 3 4 5 Incorrect c. 0 is printed infinitely d. Error
Q.7
void main( )
{ int sum=0,n=8;
do
{ sum=n%2;
n/=2;
printf(“%d”, sum);
}while(n);
}
a. 0000 b. 1000 c. 0001 d. 000
Q. 8
void main( )
{ int i=0;
for(;i<=3; printf(“%d ”, ++i ) );
}
a. 1 2 3 b. 1 2 3 4 c. 0 1 2 3 d. Error
Q.9
while(k<=5) printf(“%d”, k++);
If k contains initially -5, then how many times above loop will execute?
a. 0 b. 10 c. 11 d. 9
19
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
}
Q.11
void main( )
{ int k=3;
while(k)
{int k=1;
printf(“%d ”, k);
k--;
}
k--;
}
a. 1 b. 3 2 1 c. Infinite loop d. Error
Question 12
void main( )
{ int x=3;
do
{printf(“%d ”, x--);
}while(x&&0);
}
a. 3 b. 3 2 1 c. 2 1 d. none
Q.13
void main( )
{ int i=0,j=-1;
for(i=1; i<=3; i++)
{ for(j = 1; j<=3; j++)
{ if(i= =j) break;
printf(“%d%d”,i, j);
}
}
}
a. 121321233132 b. 213132 c. 111213212223313233 d. No output
Q.14
void main( )
{ int i, j;
for(i=1; i<=3; i=i+2)
for(j=1; j<=3; j=j+2)
printf(“%d”, i+j );
}
a. 2 4 4 6 b. 1 2 2 3 c. Infinite loop d. No output
Q.15
void main( )
{ char ch='\0';
20
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
while( ch<=127) { printf(“%c %d ”, ch++, ch ); }
}
a. Prints 127 ASCII char b. Prints entire ASCII table
c. Inifinite loop d. No output
Q.16 In worst case, how many times will do – while loop executes (minimum)?
a. 0 b. 1 c. n times d. infinite
Q.17
void main( )
{ int k=3;
while(k)
{ int K=1;
printf(“%d”, k);
k--;
}
}
a. 1 b. 3 2 1 c. Infinite loop d. Error
Q.18
void main( )
{ int no=123;
while(no)
{ no/=10;
printf(“%d”, no%10);
}
}
a. 2 b. 210 c. 21 d. 213
Q.20
void main( )
{ int i=1;
while(i<=32767)
{ printf(“%d ”, i);
i++;
}
}
a. 1 2…..32766 b. 1 2…..32767 c. 1 2…..32768 d. Infinite loop
Q.21
void main( )
{ int i=0j=1;
for(i=1,j=0; j<i; i++, j++)
21
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
{ if(i= =j) goto label2;
else printf(“%d”, i);
}
label2: printf(“%d”, j);
}
a. 1 b. 1….3276732767 c. 1….32767 d. Infinite loop
Q.25
void main( )
{ int i=0;
for(i=1;;i++)
if(i= =5)
{ printf(“%d”, i);
break;
}
else
{ printf(“%d”,i++);
continue;
}
}
a. 12345 b. 246 c. 135 d. Error
Q.27 In do while loop, 5th time condition is checked & now resulted into false, so how
many times loop has executed?
a. 4 b. 5 c. 6 d. 0
22
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
b. loop expression, loop statements, loop condition
c. loop statements, loop condition, loop expression
d. loop condition, loop statements, loop expression
Q.31
void main( )
{
While (1) printf(“USM C”);
}
a. condition in while loop is illegal b. ‘USM C’ will be printed once
c. while loop is an inifinite loop d. Linker error is generated
Q.34
void main( )
{
int j=1;
for(;j<=3; j++) printf(“%d”, j);
}
a. 0 b. 123 c. Inifinite loop d. No output
Q.35
void main( )
{ int i=2j=3;
do
{ if(j= =i)
{ printf(“less”); break;
}
j+=i;
printf(“more”);
}while(i!=j-3);
}
a. less b. more c. ‘more’ is printed thrice d. Infinite loop
Q.36 In while loop, 7th time condition is checked & now resulted into false, so how many
iterations executed?
a. 0 b. 5 c. 6 d. 7
Q.37
23
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
void main( )
{ int j=1;
while( j<=255)
{ printf(“%c %d ”, j, j );
j++;
}
}
a. Prints garbage b. Prints ASCII table c. Infinite loop d. No output
Q. 38 Which loop does not require to write ‘;’ after loop condition?
a. while b. do while c. for d. none
Q.39
void main( )
{
char ch=49 - '1';
while(++ch) putch(ch);
}
a. Prints all ASCII chars except last b. Prints all ASCII char except First
c. Inifinite loop d. No output
Q.41
void main( )
{
int i=0;
while(++i<5) printf(“%d”, ++i);
}
a. 24 b. 1234 c. 246 d. Error
Q. 42
void main( )
{
while(4<5) printf(“hi!”);
}
a. hi! b. hi! Printed infinitely c. No output d. Error
Q. 43
void main( )
{
int i=0;
for(i=1;i<=4,i++)
{ if(i= =2) continue;
else
{ printf(“%d”, i);
24
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
break;
}
}
}
a. 1 3 4 b. 1 2 3 c. 1 d. 2
Q. 45 In for loop, more than one initializations or loop expressions are separated using____.
a. ; b. , c. blank d. tab
Q.46
void main( )
{
int i=10;
for(;;) i++ printf(“hello!”);
}
a. hello! b. ‘hello!’ is printed 10 times c. Infinite loopd. Error
Q.49
Which loops are similar in behavior?
a. for & do while b. while & do while c. while & for d. do while, for & while
Q. 50
void main( )
{
int i=0, j=0;
while(j= =i)
{ printf(“%d %d ”, i, j);
i++; j--;
}
}
a. 1 1 b. 0 1 0 1 0 1 c. 0 0 d. Infinite loop
Functions
Q.1What is true regarding a return statement in a function?
Select one:
a. There cannot be more than one return statements in a function
b. A return statement must be written at the end of the function
25
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
c. A function may not have return statement
d. All the above are true
Q.2 How many times & when memory is allocated to formal parameters?
a. Only once during compilation time
b. Only once during execution time, at the start of program
c. Only once during executing time, before function call
d. For every call of that function
Q. 9 How many values can be returned from a function using return statement?
a. only 1
b. maximum 2
c. As many we want, by writing more than one return statements
d. As many we want, by using comma operator
26
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
d. A C program can be written without functions
Q.13 During execution, parameters passed to the program are received by function______.
a. that is defined as main b. that is defined 1 c. that is declared 1
27
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
a. Changes made in formal Parameters are reflected in actual parameters
b. Changes made in formal Parameters are not reflected back in actual parameters
c. Addresses of actual parameters are passed to formal parameters
d. Values of actual parameters are passed to local variables of a called function
Q.25 In recursive functions, how many times memory is allocated to its local variables?
a. Only once before that function is called
b. Depends on no. of recursive calls at runtime
c. Depends on how many times function is called in a program
d. Only once during compilation time
{ int a[ ]={10,20,30,40,50}, j;
}
a. Error : L value required b. 10 20 30 40 50
c. Garbage value printed 5 times d. 10 10 10 10 10
Q.3
void main( )
28
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
{ int ary[2];
ary[-2]=2;
printf(“%d”, ary[2-4] );
}
a. 2-4 b. garbage c. Error d. 2
Q. 4
int num[5];
Num[5]
What is true about above two statements?
a. Both statements indicate array size
b. 1st statement indicates array size & 2nd indicates element
c. Both statements indicate element of an array
d. 1st statement indicates element & 2nd indicates array size
Q.8
void main( )
{
char dac[ ];
dac[0]=65;
printf(“%c”, dac[0] );
}
a. 65 b. A c. Error d. a
Q.10
void main( )
{
int a[ ]={20,30,40,50,60}, *j=a;
j+=3;
29
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
printf(“%d”,*j);
}
a. 50 b. 20 c. Compilation Error d. 40
Q.13
char *fun( )
{
char result[100]="Hello world";
strcpy(result, “Anything is Good”);
return result;
}
void main( )
{
char *j;
j=fun( );
printf(“%s”, j);
}
a. Compilation Error b. Hello world c. Garbage d. Anything is Good
Q.14
void main( )
{
char a[6*3/2]={‘a’, ‘b’, ‘r’, ‘d’, ‘c’};
printf(“%c”, a[3] );
}
a. c b. Compilation Error c. d d. r
Q. 15
void main( )
{
char p[5]={0,0,65,66};
printf(“%d %d”, p[1], p[4]);
}
a. 0 66 b. 0 garbage c. Error d. 0 0
Q. 16
void main( )
{ int a[ ]={10,20,30,40,50}, i,*k;
k=&a[3]-3;
for (i=0;i<=4;i++)
{ printf(“%d”, *k); k++;
30
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
} }
a. 10 20 30 b. Error c. 10 20 30 40 50 d. 10 20 30 40
Q.17
void main( )
{
int M[12]; M[0]=-12; M[11]=-12;
printf(“%d %d %d”, *(M+0), *(M+11), *M );
}
a. -12 -12 12 b. 0 11 garbage c. -12 12 -12 d. -12 -12 -12
Q.19
void main( )
{
int i=10;
char ch='F', str[10]=" Born To Code";
sprintf(str,"%d %c",i, ch);
printf("%s",str);
}
a. 10 F b. 10 F BornToCode c. Error d. Born To Code
Q.20
void main( )
{ char names[]={“Aditi”, “Satish”, “Dipti”, “Sohan”, “Mohan”};
char *t; int i;
t=names[3];
names[3]=names[4];
names[4]=t;
for(i=0;i<=4;i++) printf(“%s” names[i]);
}
a. Aditi Satish Dipti Mohan Sohan b. Aditi Satish Dipti Mohan Mohan
c. Aditi Satish Sohan Dipti Mohan d. Error
Q. 23
void main( )
31
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
{ char a[12]={‘U’,‘s’,‘m’, ‘C’,‘o’,‘m’,‘p’,‘u’,‘t’,‘e’,‘r’};
printf(“%s”, a);
}
a. Usm Computer garbage b. Error c. Usm d. Usm Computer
Q.25
void main( )
{
char *dest,*source=“USM ITS”;
dest=malloc(strlen(source));
strcpy(dest, source);
printf(“%s”, dest);
free(dest);
}
a. free( ) fails b. USM ITS c. Compilation error d. strcpy( ) fails to copy string
Q. 27
void main( )
{
int n[3][3]={2,4,6,8,5,3,5,1}, *ptr ,i;
Ptr=&n[1][0];
for(i=0;i<=3;i++) printf(“%d”, *(ptr+i));
}
a. 3 6 8 5 b. 8 5 3 5 c. 6 3 garbage garbage d. 5 3 5 1
Q.28 Which header file should be included for using standard string functions?
a. string.c b. stdlib.h c. string.h d. stdio.h
32
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
a. Array name is a variable pointer storing starting address of an array
b. Array name is a constant pointer storing addresses of all array locations
c. Array name is not a pointer
d. Array name is a constant pointer storing starting address of an array
Q.38
void main( )
{ int i, fun1( ), fun2( ), fun3( );
int (*f[3])( );
f[0]=fun1; f[1]=fun2; f[2]=fun3;
for(i=0;i<3;i++) (*f[i]) ( );
}
fun1( ) { printf(“USM”); fun2( ); }
fun2( ) { printf(“COMPUTER”); }
fun3( ) { printf(“EDUCATION”); }
a. USM COMPUTER EDUCATION
b. USM COMPUTERCOMPUTEREDUCATION
c. USM COMPUTER
d. Error
Q.39
void main( )
{ char usm[1]={‘2’};
usm++;
printf(“%d”, usm );
}
a. 3 b. Error c. garbage d. 51
Q.40
void main( )
{ int s[2][ ]={3,4,5,6,7,8,9,10};
printf(“%d”, s[1][2] );
}
a. 8 b. Error c. 6 d. 9
33
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
Structure and Union
Q.1 Which storage class can be used to speed up process?
a. auto b. static c. extern d. register
Q.3 How many storage classes can be used for a variable at a time?
a. 0 b. 1 c. 2 d. 4
Q.4 Which is not a register?
a. AX b. SI c. ZX d. DS
Q.5 _______storage class variable can have one definition & multiple declarations?
a. auto b. static c. extern d. register
Q.6 Which of the following variable do not have default initial value Zero?
a. global b. extern c. static d. none of the above
Q.7 Consider following declaration Struct DAC {int j; union { double ACTS; int p; }mum; }*USM; How to access
ACTS through USM?
a. USM->mum->ACTS b. USM->mum.ACTS
c. USM.mum->ACTS d. USM.mum.ACTS
Q. 8 void main( ) { long n=2.5; int m=3; long int p=m+n; printf(“%d”, p);
a. 5 b. 5.5 c. 5.0 d. Compilation error
Q.9
struct s
{ char ch; int j;
};
display (struct s *x1)
{
printf(“%d %c”, x1->j, x1->ch);
}
void main( )
{
static struct s s1 ={‘S’,1}, s2={‘R’,4}; s2=s1; display(&s2);
}
a. 1 S b. 4 R c. Error: “s2=s1” d. Error: “x1->j,x1->ch”
Q.10
struct PP
{ int k; char c; };
QP(struct PP a);
void main( )
{
struct PP n= {110,65}; QP(n); } QP(struct PP a) { printf(“%d ..%c” a.k, a.c);
34
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
}
a. 110…65 b. 110…A c. Error d. 65…65
Q.12
void main( )
{ stuct s1 { char *z; int I; struct s1 *p; };
static struct s1 a[ ] = {{“Kerala”, 6, a+2},{“Punjab”,5,a+1}, {“Delhi”,4,a}};
struct s1 *ptr=a+1;
printf(\n%s%s%s”, a[0].z, ptr->z, a[2].p->z);
}
a. Kerala Kerala Kerala b. Kerala Punjab Delhi
c. Kerala Punjab Punjab d. Kerala Punjab Kerala
Q.13
void main( )
{
auto i=5.5; register n=5.5;
Printf(“%d %d”, i, n);
}
a. 5.5 5.5 b. 5 5.5 c. 5.5 5 d. 5 5
Q. 14
int check1(int a)
{
return(++a);
}
int check2(int a)
{return(a++);
}
void main( )
{
static int x=1;
printf(%d”, check1(x));
printf(“%d”, check2(x));
}
a. 22 b. 23 c. 12 d. 21
35
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
Q.15
void main( )
{
double long x=0;
printf(“%lf”, x);
}
a. 0.000000 b. 0 c. Illegal datatype d. Illegal Format specifier
Q.16
void main( )
{
register double sum;
printf(“%d”, sizeof(sum));
}
a. 4 b. 2 c. 8 d. Invalid datatype
Q.17
static int x=3, y, z;
void main( )
{
int a; a=x++ * ++y +++z;
printf(“%d”, a);
}
a. 3 b. 4 c. 5 d. Garbage
Q. 18
void main( )
{
signed char c=`11’;
printf(“%d %c”, c, c);
}
a. 59 11 b. 49 1 c. 49 11 d. 49 – 11
Q.19
int FUN=100
main( )
{
extern int FUN=200;
printf(“%d”, x);
}
a. 100
b. 200
c. FUN should be of datatype: ‘int extern’
d. extern variable can not be initialized
Q.20
static char ch=`a’;
36
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
void main( )
{
extern char ch;
{ ch=`b’;
}
printf(“%c”, ch);
}
a. a b. b c. Garbage d. Compilation error
Q.21
int fin;
int init;
int call1(int c) {return(c++); }
int call2(int c) {return(++c); }
void main( )
{
register int fin;
printf(“%d”, init);
fin=call1(init);
printf(“%d”, fin);
fin=call2(init);
printf(“%d”, fin);
}
a. 001 b. 011 c. 012 d. Error
Q. 22
static int k=15,
m=20; change( )
{
printf(“%d %d”, k, m);
}
void main( )
{
static int k=2, m=1;
printf(“%d %d”, k, m);
change( );
}
a. 2 1 2 1 b. 2 115 20 c. 15 20 15 20 d. 2 10 0
Q.23
auto int ai;
void main( )
{
ai=ai+10;
printf(“%d”, ai);
}
a. 10 b. Garbage c. 0 d. Compilation error
37
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
Q.24
add( )
{
static char ch='n';
printf(“%c”, ch);
ch=ch-2;
}
void main( )
{ add( );
add( );
add( );
}
a. n n n b. j 1 n c. n 1 j d. n 1 k
Q.25
enum records
{
one, two=4, three, four=4};
void main( )
{
printf(“%d,%d,%d,%d”, one, two, three, four);
}
a. 0,4,5,4 b. 1,4,3,4 c. 1,4,5,4 d. Error
Q.26
void main( )
{
enum days {mon,tue,wed,sat,USM};
enum days d1,d2,d3; d1=mon+USM;
d2=wed-sat; d3=USM*tue;
printf(“%d %d %d”,d1,d2,d3);
}
a. 4 -1 4 b. 1 5 5 c. 0 4 4 d. Compilation error
Preprocessor
Q.1 Which header file is not available in standard library?
a. string.h b. ctype.h c. matrix.h d. time.h
38
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
Q.3 #define SQUARE(x)=(x*x); #define csi(m,n) (SQUARE(m)>SQUARE(n) ? n : m) void main( ) { int s; s=csi(2,-3);
printf(“%d”,s); }
a. 2 b. -3 c. 4 d. error
Q.4 #define CASE (a>=65&&a<=90) void main( ) { char b='Q'; if(CASE) printf(“Upper case”); else printf(“Lower
case”); }
a. Lower case b. Upper case c. Compilation error d. None of these
Q.6 #define HEADERFILE “conia.h” #include HEADERFILE void main( ) { window(10, 10,40,20); cprintf(“USM
COMPUTER EDUCATION”); cprintf(“A PERFECT WAY TO IT”); }
a. USM COMPUTER EDUCATIONA PERFECT WAY TO IT
b. USM COMPUTER EDUCATION
c. USM COMPUTER EDUCATION A PERFECT WAY TO IT
d. Compilation error
Q. 8 # define square(x) (x*x) void main( ) { int a,b=3; a=square(b+2); printf(“%d”, a); }
a. 25 b. 9 c. 11 d. Garbage
Q. 9 #define MAIN main( ) #define BEGIN { #define END } MAIN BEGIN printf(“Good Morning”); END
a. You can not redefine main b. No output c. Good Morning d. Compilation error
Q. 11 #define mult(x) x*x int mul(x) {return x*x; } void main( ) { int m,i=3; m=mul(i+2); printf(“%d”,m);
m=mult(2+i); printf(“%d”,m); }
a. 1125 b. 2511 c. 117 d. 257
Q.12#define P(format, var) printf(“var=%format ”,var); void main( ) { int i=3; float a=3.14; p(d,i); P(f,a); }
a. var=3format var=3.140000ormat b. var=0.000000ormat var=3.140000ormat
c. var=3 var=3.140000ormat d. Error
Q. 13 #define D void main( ) { int i=2; #ifdef D printf(“%d”,i*=i); #else printf(“%d”,i); #endif }
a. 2 b. 4 c. 16 d. Compilation error
Q.14 #define Ptr int * Void main( ) { Ptr P, Q; int a=3,b=5; P=&a; Q=&b; *P=*P + *Q; *Q=*P - *Q; *P=*P - *Q;
printf(“%d %d”,a, b); }
39
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
a. 3 5 b. 5 3 c. 8 3 d. Error
Q. 15 #define is________.
a. a pre-processor b. a macro itself c. a preprocessor directive d. a template
Q.16 #define prod(a,b) a*b void main( ) { int z, x=2,y=3; z=prod(x+2,y-1); printf(“%d”,z); }
a. 8 b. 7 c. 0 d. None of above
Q. 17
#define square(x, y) (x+y)
void main( )
{
int i,a=4,b=3;
i=add(a+4,1+b);
printf(“%d”,i);
}
a. 14 b. 13 c. 12 d. Compilation error
Q.19
/* include file zzz.h starts here */ printf(“Hello”); /* include file zzz.h ends here */ void main( ) { #include “zzz.h”
printf(“World”); }
a. World b. Hello c. Hello World d. Compilation error
Q.20 #define IMP #ifdef IMP int = 10; #endif; void main( ) { int = 5; printf(“%d”,IMP); }
a. 10 b. 0 c. 5 d. Error
Q. 22 #define D void main( ) { int i=2; #ifdef D printf(“%d”,i*=i); #else printf(“%d”,i); #endif }
a. 2 b. 4 c. 16 d. Compilation error
Q.23 Macro definition can be extended on more than one lines using character______.
a. / b. \ c. # d. %
Q.24
#define calc(a) (a*a*a); void main( ) { float i=2.0,p=0; p=calc(i); printf(“%f”, p); if(calc(i)= =8) printf(“cube”); }
a. 8 b. 8.000000cube c. 8.000000 d. Compilation error
Q.25
#define NOW #define LATER void main( ) { #ifdef NOW & & LATER printf(“We will go for movie”); #else
printf(“We will not go”); #endif }
a. We will not go b. We will go for movie c. Compilation error d. None
40
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
Q.26 Which of the following statement is true regarding macros and functions?
a. Macros and functions are same
b. Macros run program faster than functions
c. Due to functions the program size increases, hence macros are preferred
d. Macros increases overheads of an activation record
Q.29 #define result(a) (a+2*3) void main( ) { int x=3,y,z; y=result(x++); z=result(++x); printf(“%d %d”, y,z); }
a. 9 11 b. 15 18 c. 15 11 d. 9 18
Q.3
void main( )
{
FILE *fp;
fp=fopen(“a.dat”,“r”);
fseek(fp, 0, 2);
printf(“%d”,ftell(fp));
fcloseall( );
}
a. 12 b. 11 c. 13 d. 9
41
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
Q.4 What is returned by function ftell( )?
a. Current position of File pointer ( offset )
b. ASCII value of Character Present at current position
c. File size
d. Character Present at current position.
Q.8
void main( )
{
FILE *fp; char ch= ‘O’;
fp=fopen(“A.dat”, “w”);
fputc(ch,fp);
fputs(“let’s study together”,fp);
}
What will be contents of file “A.dat” after executing above program?
a. O b. O let’s study together c. let’s study together d. Error in Program
Q.9
void function(FILE *fp )
{
fp=fopen(“dummy.dat”,“w”);
}
void main( )
{
FILE *fp
function(fp);
fprintf(fp,“%s”,“Hi !”);
fclose(fp);
42
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
}
what will “dummy.dat” contain?
a. Nothing b. Hi c. Garbage d. Runtime error
Q.11 Which of the following file opening mode deletes contents of file, if it already exists?
a. “wb” b. “wb+” c. All of these d. “w”
Q.13
void main( )
{
FILE *fp;
fp=fopen(“C:\My Documents\a.dat”,“w”);
if(!fp) exist(1);
fclose(fp);
}
point out error in the above code
a. Path provided in function fopen( )
b. The function fclose( ) must have the filename as parameter
c. The above code will compile successfully
d. The file should be closed before exit( )
Q.15
void main( )
{
FILE *fp;
fp=fopen(“a.dat”,“r”);
fseek(fp,-1, 2);
printf(“%c”,fgetc(fp));
fclose(fp);
}
a. i b. EOF c. h d. garbage
Q.16
void main( )
{
FILE *fp;
char ch=0,cnt=0;
fp=fopen(“a.dat”,“r”);
43
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
while((ch=fgetc(fp))!=EOF) cnt++;
printf(“%d bytes”,cnt);
}
a. 10 bytes b. 13 bytes c. 9 bytes d. 11 bytes
Q.18 What will happen if specified file does not exist while opening that file in program(fopen)?
a. Different Action will be taken Depending on file opening mode
b. Function fopen will return NULL
c. It will create new File
d. It will generate Runtime Error
44
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
Q.24 Which of the following can not take file pointer to beginning Of File?
a. fopen b. fflush c. fseek d. rewind
Q.25 Which one function can be used to close all files f1, f2, f3 having their file pointers fp1, fp2, fp3
respectively?
a. fcloseall( ); b. fclose(f1,f2,f3); c. fclose( ); d. fclose(fp1,fp2,fp3);
Q.30 Which function can be used to write entire structure in binary file?
a. fputc b. fprintf c. fputs d. fwrite
Q.31
void main( )
{
unsigned char ch;
FILE *fp;
fp=fopen(“alpha.dat”, “r”);
while((ch=fgetc(fp))!=EOF) putchar(ch);
fclose(fp);
}
a. It will display contents of file alpha.dat & then it will go in infinite loop
b. It will go in infinite loop
c. Error
45
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
d. It will display contents of file alpha.dat
Q. 32 Which Standard Function/Macro is used to check end of file?
a. feof b. fend c. eof d. EOF
Q.33
void main( )
{
char ch;
chrscr( );
ch=getche( );
fprintf(stdout,“%c”, ch);
}
While executing above code, ‘s’ is typed then what will be seen on screen?
a. No output b. s s c. Garbage d. s
Q.34 Which header file is required for using file handling functions?
a. conio.h b. stdio.h c. stdfile.h d. stdlib.h
Q.40. #include<stdio.h>
void main( )
46
Shriram Mantri Vidyanidhi Info Tech Academy
C Programming Question Bank
{
printf(“%#X”,EOF);
}
a. 0XFFFF b. 0xFF c. FF d. 0X10
47