C-PROGRAMMING PART 1 (quiz 1)





1) What is the output this code?

#include<stdio.h>

int main()

{        

          int i=1,2.3;

          printf("%d",i);

}

A) Object file will be created for this C code

B) 1

C) 1,2.3

D) Compilation Error

Answer: D) Compilation Error



2)What gets printed when the code

is executed?

#include<stdio.h>

int main()

  int i=1,c9;

printf("%d",i);

}

A) 1,c9

B) 1

C) 1,

D) Compilation Error


Answer: B) 1



3)Which function is used to clear the

input buffer?

A) FFLSUH(stdin)

B) Both C & D

C) __fpurge(stdin)

D) fflush(stdin)


Answer:

B) Both C & D

__ fpurge -- Ubuntu

fflush -- Windows



4)What gets printed?

#include<stdio.h>

int main()

{  int j = 5;

    printf("%d",++5);

}

A) 5

B) 6

C) Runtime Error

D) Compilation Error


Answer: D) Compilation Error



5) 

int main()

{

int i=4;

int j=sizeof(i++);

printf("%d %d\n",j,i);

return 0;

}

Assume the size of integer is 4 bytes.

What is printed when the above code is executed?


Answer: 4 4

sizeof is an operator



6)What gets printed?

#include<stdio.h>

int main()

{ float f=11.4;12.5;

   printf("%f",f);

}

A) Compile-time Error

B) 11.4

C) 12.5

D) Runtime Error


Answer: A) Compile-time Error



7)What gets printed?

#include<stdio.h>

int main()

{ float f=11.4; 12.5;

printf("%f",f);

}

A) Compilation Error

B) 11.400000

C) 12.5

D) 11.4

E) Runtime Error


Answer: B) 11.400000



8)

float f = 23.5;

float *fp = &f;

printf("%9.1f",*fp);

What is the output of above code?


A) 23.500000

B) Compilation Error

C) 23.5

D) Undefined Behaviour


Answer: C) 23.5



9)What gets printed?

#include<stdio.h>

int main()

{

if(1==1)

if(0)

printf("zero");

printf("one");

}

A) zero many times

B) zeroone

C) zero

D) one

E) No output


Answer: D) one



10)What gets printed when the below code is

executed ?

int a = 100;

a == 100 || ++a == 101;

printf("%d", a);


A) Error B) 101 C) 100 D) undefined


Answer: C) 100

|| performs short circuit evaluation. Second expression

will never be executed if first expression results in 1



11)What gets printed?


int a = 100;

a == 100 && ++a == 101;

printf("%d", a);


A) Error B) 101 C) 100 D) undefined


Answer: B) 101


&& performs short circuit evaluation. Second

expression will never be executed if first expression

results in 0



12)What gets printed?

int a = 100;

a++ == 100 && a++ == 101;

printf("%d", a);


A) 102 B) 101 C) 100 D) undefined


Answer: A) 102


|| and && supports sequence point operation. All side

effects are completed before second expression is

executed.



13)What is the output?

int a = 100;

printf("%d ", ++a == 100 || a++ == 101);

printf("%d", a);

A) 101 1

B) 1 102

C) 102 1 

D) 0 102

E) Undefined values


Answer: B) 1 102



14)What is the output?

int a = 100;

(a>100) ? (a = a-10) : (a = a+10);

printf("%d", a);


A) 90

B) 110

C) Compile time Error

D) Undefined value


Answer: B) 110



15)What is the output?

int a;

printf("%d",sizeof(a=2));

What is printed when the above code

is executed?

A) Compilation Error

B) Depends on the implementation

C) 4

D) 2


Answer: B) Depends on the implementation



16)

printf("%d",sizeof(‘\t’));

What is printed ?

A) Compilation Error

B) 1

C) 2

D) 0


Answer: B) 1



17)

int i;

int j;

char k;

scanf("%d,%d %c",&i,&j,&k);

printf("%d, %d, %d",i,j,k);


What is the output of the code when user enters

12,65 A and presses enter key.


Answer: 12, 65, 65



18)

int i,j;

scanf("%d*%d",&i,&j);

printf("%d*%d",i,j);

If the user enters 8*9, What is the output?


Answer: 8*9



19)Pick the odd one out

A) *

B) **

C) ^

D) //

E) Both B and D


Answer: E) Both B and D


** and // do not exist in C as stand alone operators

** - > Unary * twice. Pointer to pointer

// -> Single line Comment in C



20)What happens when the below code is executed?

int a = 10;

for (;a==10;)

{

printf("%d ",a);

a--;

}

A) Output is 10 infinite times

B) Output is 10

C) Output is 10 to 1 in decreasing order.

D) Compilation Error


Ans: B) Output is 10



21)

char s;

while( (s = getchar()) != '\n')

{

if(s = ‘a')

putchar('s');

putchar(s);

}


input : pes and then press enter key

output: ?


A) sssa

B) sasasa

C) pesa

D) Error


Ans: B) sasasa



22)

int n; n = 2; 

switch(n)

{

default : printf("none"); break;

case 2 : printf("one");

case 3 : printf("two");

}


What gets printed?

A) noneonetwo

B) onetwo

C) one

D) none


Ans: B) onetwo

Expression matches with case 2. But no break for it. So

rest all will be executed till it finds the break.



23)

printf("%d",23.0%2);

What is the output?

A) 1

B) Undefined Behaviour

C) Compile – time Error

D) Link Time Error


Answer: C) Compile – time Error



24)

int n = 7;

 switch(n) 

{

case n < 7 : printf("lesser");

case n == 7 : printf("equal"); break;

default : printf("more"); break;

}

A) Output is more

B) Output is equal

C) Output is lesserequal

D) Syntax Error


Answer: D) Syntax Error. Case labels cannot have

relational operators used in it.

It allows only integral constants


25)

int n = 7; 

switch(n>1) 

{

default : printf("more"); break;

case 1: printf("lesser");

case 7 : printf("equal"); break;

}


A) Output is more

B) Output is lesser

C) Output is lesserequal

D) Syntax Error


Answer: B) output is lesserequal


Expression n>1 returns in 1. This matches

with case label 1. No break for it



26)

int n = 0; 

switch(n>1)

{

default : printf("more"); break;

case 1: printf("lesser");

case 7 : printf("equal"); break;

}

A) morelesserequal

B) more

C) lesserequal

D) Compile Time Error


Answer: B) more



27)

If the object file is first.o, how to name the

loadable image as first.out during linking

stage?


Answer: gcc first.o –o first.out



28) What is the output of the code?

#include<stdio.h>

int main()

 Printf(“Is there any error?”);

 return 0;

}

A) Compilation Error

B) Is there any error?

C) Link time Error

D) Logical Error


Answer: C) Link time Error



29)

int age_$1 = 111;

printf("%d",age_$1);


A) Compilation Error

B) 111

C) 111.000000

D) None of these


Answer: B) 111



30)

int a = 111;

sizeof(a);

printf("%d",a);

A) Compilation Error

B) 111

C) 111.000000

D) Implementation specific


Answer: B) 111



31) Say True or False.

Colon(:) is a statement terminator in C.


Answer: False



32)

int b = 167;

int *bp = &b;

printf("%d %d %d %d %d" ,bp, *bp, b, &b,&bp);


Which of the outputs doesn’t have any

match?


A) bp

B) b

C)&bp

D) *bp


Answer: C) &bp



33) Pick the odd one out .

Hint: lvalue and rvalue

A) sizeof

B) +

C) &

D) *


Answer: D) *. This can be used as Lvalue

and rvalue. Others only rvalue



34)what is the output of this?

for(;;)

{

printf(“Chocolate”);

}

A) Chocolate printed once

B) Chocolate printed in an infinite loop

C) Compile Time Error

D) None of these


Answer: B) Chocolate printed in an infinite loop



35)what is the output of this?

int n = 12;

for (;;n--);

{

printf("Chocolate");

}

A)No output . Infinite loop

B) Chocolate printed once

C) Compile Time Error

D) Chocolate printed in an infinite loop


Answer: A)No output . Infinite loop



36) 

int n = 5; int f = 1;

while(n--)

{

f *= n;

}

printf("what : %d\n", f);


What gets printed?

A) Output of 5*5*5*5*5

B) output of 5!

C) output of (5*4)*(4*3)*(3*2)*(2*1)

D) output of 5*4*3*2*4*1*0

E) output of 4*3*2*4*1


Answer: D)



37) Display the below statement in one line

using a single printf.

"\n and \r are escape sequences. %d is

format specifier for int"


Answer:

printf("\"\\n and \\r are escape sequences.

%%d is format specifier for int\"");



38)

char d;

int i = 0;

while ((d=getchar()) != '\t')

{

   //suite

}

How many times the suite of the loop is

executed when the input is chocolate with

enter key?Will the execution of code get

terminated after this? 


Answer: 10

No. User can give more inputs till

tab(\t) is the input




darkmode