34
1. How many times "IndiaBIX" is get printed? #include<stdio.h> int main() { int x; for(x=-1; x<=10; x++) { if(x < 5) continue; else break; printf("IndiaBIX"); } return 0; } A. Infinite times B. 11 times C. 0 times D. 10 times 2. How many times the while loop will get executed if a short int is 2 byte wide? #include<stdio.h> int main() { int j=1; while(j <= 255) { printf("%c %d\n", j, j); j++; } return 0; } A. Infinite times B. 255 times C. 256 times D. 254 times 3. Which of the following is not logical operator? A. & B. && C. || D. ! 4. In mathematics and computer programming, which is the correct order of mathematical operators ? A. Addition, Subtraction, Multiplication, Division B. Division, Multiplication, Addition, Subtraction C. Multiplication, Addition, Division, Subtraction D. Addition, Division, Modulus, Subtraction 5. Which of the following cannot be checked in a switch-case statement? A. Character B. Integer 1

c Language Object Types

Embed Size (px)

Citation preview

Page 1: c Language Object Types

1.  How many times "IndiaBIX" is get printed?

#include<stdio.h>int main(){ int x; for(x=-1; x<=10; x++) { if(x < 5) continue; else break; printf("IndiaBIX"); } return 0;}

A. Infinite times B. 11 times

C. 0 times D. 10 times

2.  How many times the while loop will get executed if a short int is 2 byte wide?

#include<stdio.h>int main(){ int j=1; while(j <= 255) { printf("%c %d\n", j, j); j++; } return 0;}

A. Infinite times B. 255 times

C. 256 times D. 254 times

3. 

Which of the following is not logical operator?

A. & B. &&

C. || D. !

4. 

In mathematics and computer programming, which is the correct order of mathematical operators ?

A. Addition, Subtraction, Multiplication, Division

B. Division, Multiplication, Addition, Subtraction

C. Multiplication, Addition, Division, Subtraction

D. Addition, Division, Modulus, Subtraction

5. 

Which of the following cannot be checked in a switch-case statement?

A. Character B. Integer

C. Float D. enum

.1.  What will be the output of the program?

1

Page 2: c Language Object Types

#include<stdio.h>int main(){ int i=0; for(; i<=5; i++); printf("%d,", i); return 0;}

A. 0, 1, 2, 3, 4, 5 B. 5

C. 1, 2, 3, 4 D. 6

2.  What will be the output of the program?

#include<stdio.h>int main(){ char str[]="C-program"; int a = 5; printf(a >10?"Ps\n":"%s\n", str); return 0;}

A. C-program B. Ps

C. Error D. None of above

3.  What will be the output of the program?

#include<stdio.h>int main(){ int a = 500, b = 100, c; if(!a >= 400) b = 300; c = 200; printf("b = %d c = %d\n", b, c); return 0;}

A. b = 300 c = 200 B. b = 100 c = garbage

C. b = 300 c = garbage D. b = 100 c = 200

4.  What will be the output of the program?

#include<stdio.h>int main(){ unsigned int i = 65535; /* Assume 2 byte integer*/ while(i++ != 0) printf("%d",++i); printf("\n"); return 0;}

A. Infinite loop

B. 0 1 2 ... 65535

C. 0 1 2 ... 32767 - 32766 -32765 -1 0

D. No output

.

5.  What will be the output of the program?

2

Page 3: c Language Object Types

#include<stdio.h>int main(){ int x = 3; float y = 3.0; if(x == y) printf("x and y are equal"); else printf("x and y are not equal"); return 0;}

A. x and y are equal B. x and y are not equal

C. Unpredictable D. No output

6.  What will be the output of the program, if a short int is 2 bytes wide?

#include<stdio.h>int main(){ short int i = 0; for(i<=5 && i>=-1; ++i; i>0) printf("%u,", i); return 0;}

A. 1 ... 65535 B. Expression syntax error

C. No output D. 0, 1, 2, 3, 4, 5

7.  What will be the output of the program?

#include<stdio.h>int main(){ char ch; if(ch = printf("")) printf("It matters\n"); else printf("It doesn't matters\n"); return 0;}

A. It matters B. It doesn't matters

C. matters D. No output

8.  What will be the output of the program?

#include<stdio.h>int main(){ unsigned int i = 65536; /* Assume 2 byte integer*/ while(i != 0) printf("%d",++i); printf("\n"); return 0;}

A. Infinite loop

B. 0 1 2 ... 65535

C. 0 1 2 ... 32767 - 32766 -32765 -1 0

D. No output

9.  What will be the output of the program?

3

Page 4: c Language Object Types

#include<stdio.h>int main(){ float a = 0.7; if(0.7 > a) printf("Hi\n"); else printf("Hello\n"); return 0;}

A. Hi B. Hello

C. Hi Hello D. None of above

10.  What will be the output of the program?

#include<stdio.h>int main(){ int a=0, b=1, c=3; *((a) ? &b : &a) = a ? b : c; printf("%d, %d, %d\n", a, b, c); return 0;}

A. 0, 1, 3 B. 1, 2, 3

C. 3, 1, 3 D. 1, 3, 1

11.  What will be the output of the program?

#include<stdio.h>int main(){ int k, num = 30; k = (num < 10) ? 100 : 200; printf("%d\n", num); return 0;}

A. 200 B. 30

C. 100 D. 500

12.  What will be the output of the program?

#include<stdio.h>int main(){ int a = 300, b, c; if(a >= 400) b = 300; c = 200; printf("%d, %d, %d\n", a, b, c); return 0;}

A. 300, 300, 200 B. Garbage, 300, 200

C. 300, Garbage, 200 D. 300, 300, Garbage

13.  What will be the output of the program?

#include<stdio.h>int main(){ int x=1, y=1; for(; y; printf("%d %d\n", x, y)) {

4

Page 5: c Language Object Types

y = x++ <= 5; } printf("\n"); return 0;}

A.

2 13 14 15 16 17 0

B.

2 13 14 15 16 1

C.

2 13 14 15 1

D.

2 23 34 45 5

14.  What will be the output of the program?

#include<stdio.h>int main(){ int i = 5; while(i-- >= 0) printf("%d,", i); i = 5; printf("\n"); while(i-- >= 0) printf("%i,", i); while(i-- >= 0) printf("%d,", i); return 0;}

A.4, 3, 2, 1, 0, -14, 3, 2, 1, 0, -1

B.5, 4, 3, 2, 1, 05, 4, 3, 2, 1, 0

C. Error D.5, 4, 3, 2, 1, 05, 4, 3, 2, 1, 05, 4, 3, 2, 1, 0

15.  What will be the output of the program?

#include<stdio.h>int main(){ int i=3; switch(i) { case 1: printf("Hello\n"); case 2: printf("Hi\n"); case 3: continue; default: printf("Bye\n"); } return 0;}

A. Error: Misplaced continue B. Bye

C. No output D. Hello Hi

5

Page 6: c Language Object Types

16.  What will be the output of the program?

#include<stdio.h>int main(){ int x = 10, y = 20; if(!(!x) && x) printf("x = %d\n", x); else printf("y = %d\n", y); return 0;}

A. y =20 B. x = 0

C. x = 10 D. x = 1

17.  What will be the output of the program?

#include<stdio.h>int main(){ int i=4; switch(i) { default: printf("This is default\n"); case 1: printf("This is case 1\n"); break; case 2: printf("This is case 2\n"); break; case 3: printf("This is case 3\n"); } return 0;}

A.This is defaultThis is case 1

B.This is case 3This is default

C.This is case 1This is case 3

D. This is default

18.  What will be the output of the program?

#include<stdio.h>int main(){ int i = 1; switch(i) { printf("Hello\n"); case 1: printf("Hi\n"); break; case 2: printf("\nBye\n"); break; } return 0;}

A.HelloHi

B.HelloBye

6

Page 7: c Language Object Types

C. Hi D. Bye

19.  What will be the output of the program?

#include<stdio.h>int main(){ char j=1; while(j < 5) { printf("%d, ", j); j = j+1; } printf("\n"); return 0;}

A. 1 2 3 ... 127

B. 1 2 3 ... 255

C. 1 2 3 ... 127 128 0 1 2 3 ... infinite times

D. 1, 2, 3, 4

20.  What will be the output of the program?

#include<stdio.h>int main(){ int x, y, z; x=y=z=1; z = ++x || ++y && ++z; printf("x=%d, y=%d, z=%d\n", x, y, z); return 0;}

A. x=2, y=1, z=1 B. x=2, y=2, z=1

C. x=2, y=2, z=2 D. x=1, y=2, z=1

1.  Point out the error, if any in the for loop.

#include<stdio.h>int main(){ int i=1; for(;;) { printf("%d\n", i++); if(i>10) break; } return 0;}

A. There should be a condition in the for loop

B. The two semicolons should be dropped

7

Page 8: c Language Object Types

C. The for loop should be replaced with while loop.

D. No error

View Answer Online Compiler Report Discuss in Forum

2.  Point out the error, if any in the program.

#include<stdio.h>int main(){ int a = 10; switch(a) { } printf("This is c program."); return 0;}

A. Error: No case statement specified

B. Error: No default specified

C. No Error

D. Error: infinite loop occurs

View Answer Online Compiler Report Discuss in Forum

3.  Point out the error, if any in the program.

#include<stdio.h>int main(){ int i = 1; switch(i) { printf("This is c program."); case 1: printf("Case1"); break; case 2: printf("Case2"); break; }return 0;}

A. Error: No default specified

B. Error: Invalid printf statement after switch statement

C. No Error and prints "Case1"

D. None of above

View Answer Online Compiler Report Discuss in Forum

4.  Point out the error, if any in the while loop.

#include<stdio.h>int main(){ int i=1; while() { printf("%d\n", i++); if(i>10) break; } return 0;}

8

Page 9: c Language Object Types

A. There should be a condition in the while loop

B. There should be at least a semicolon in the while

C. The while loop should be replaced with for loop.

D. No error

View Answer Online Compiler Report Discuss in Forum

5.  Which of the following errors would be reported by the compiler on compiling the program given below?

#include<stdio.h>int main(){ int a = 5; switch(a) { case 1: printf("First");

case 2: printf("Second");

case 3 + 2: printf("Third");

case 5: printf("Final"); break;

} return 0;}

A. There is no break statement in each case.

B. Expression as in case 3 + 2 is not allowed.

C. Duplicate case case 5:

D. No error will be reported.

View Answer Online Compiler Report Discuss in Forum6.  Point out the error, if any in the program.

#include<stdio.h>int main(){ int P = 10; switch(P) { case 10: printf("Case 1");

case 20: printf("Case 2"); break;

case P: printf("Case 2"); break; } return 0;}

A. Error: No default value is specified

B. Error: Constant expression required at line case P:

C. Error: There is no break statement in each case.

D. No error will be reported.

9

Page 10: c Language Object Types

View Answer Online Compiler Report Discuss in Forum

7.  Point out the error, if any in the program.

#include<stdio.h>int main(){ int i = 1; switch(i) { case 1: printf("Case1"); break; case 1*2+4: printf("Case2"); break; }return 0;}

A. Error: in case 1*2+4 statement

B. Error: No default specified

C. Error: in switch statement

D. No Error

8.  Point out the error, if any in the while loop.

#include<stdio.h>int main(){ void fun(); int i = 1; while(i <= 5) { printf("%d\n", i); if(i>2) goto here; }return 0;}void fun(){ here: printf("It works");}

A. No Error: prints "It works"

B. Error: fun() cannot be accessed

C. Error: goto cannot takeover control to other function

D. No error

9.  Point out the error, if any in the program.

#include<stdio.h> int main(){ int a = 10, b; a >=5 ? b=100: b=200; printf("%d\n", b); return 0;}

A. 100 B. 200

10

Page 11: c Language Object Types

C. Error: L value required for b D. Garbage value

1.  Which of the following statements are correct about the below program?

#include<stdio.h>int main(){ int i = 10, j = 20; if(i = 5) && if(j = 10) printf("Have a nice day"); return 0;}

A. Output: Have a nice day

B. No output

C. Error: Expression syntax

D. Error: Undeclared identifier if

2.  Which of the following statements are correct about the below program?

#include<stdio.h>int main(){ int i = 10, j = 15; if(i % 2 = j % 3) printf("IndiaBIX\n"); return 0;}

A. Error: Expression syntax B. Error: Lvalue required

C. Error: Rvalue required D. The Code runs successfully

3.  Which of the following statements are correct about the program?

#include<stdio.h>int main(){ int x = 30, y = 40; if(x == y) printf("x is equal to y\n");

else if(x > y) printf("x is greater than y\n");

else if(x < y) printf("x is less than y\n") return 0;}

A. Error: Statement missing B. Error: Expression syntax

C. Error: Lvalue required D. Error: Rvalue required

4.  Which of the following statements are correct about an if-else statements in a C-

program?

1: Every if-else statement can be replaced by an equivalent statements using ? ; operators

2: Nested if-else statements are allowed.

3: Multiple statements in an if block are allowed.

4: Multiple statements in an else block are allowed.

A. 1 and 2 B. 2 and 3

11

Page 12: c Language Object Types

C. 1, 2 and 4 D. 2, 3, 4

5.  Which of the following statements are correct about the below program?

#include<stdio.h>int main(){ int i = 0; i++; if(i <= 5) { printf("IndiaBIX\n"); exit(0); main(); } return 0;}

A. The program prints 'IndiaBIX' 5 times

B. The program prints 'IndiaBIX' one time

C. The call to main() after exit() doesn't materialize.

D. The compiler reports an error since main() cannot call itself.

6.  Which of the following statements are correct about the below C-program?

#include<stdio.h>int main(){ int x = 10, y = 100%90, i; for(i=1; i<10; i++) if(x != y); printf("x = %d y = %d\n", x, y); return 0;}

1 : The printf() function is called 10 times.

2 : The program will produce the output x = 10 y = 10

3 : The ; after the if(x!=y) will NOT produce an error.

4 : The program will not produce output.

A. 1 B. 2, 3

C. 3, 4 D. 4

7.  Which of the following sentences are correct about a for loop in a C program?

1: for loop works faster than a while loop.

2: All things that can be done using a for loop can also be done using a whileloop.

3: for(;;); implements an infinite loop.

4: for loop can be used if we want statements in a loop get executed at least once.

A. 1 B. 1, 2

C. 2, 3 D. 2, 3, 4

8.  Which of the following statements are correct about the below program?

#include<stdio.h>int main(){ int n = 0, y = 1; y == 1 ? n=0 : n=1; if(n) printf("Yes\n"); else

12

Page 13: c Language Object Types

printf("No\n"); return 0;}

A. Error: Declaration terminated incorrectly

B. Error: Syntax error

C. Error: Lvalue required

D. None of above

9.  Which of the following sentences are correct about a switch loop in a C program?

1: switch is useful when we wish to check the value of variable against a particular set of values.

2: switch is useful when we wish to check whether a value falls in different ranges.

3: Compiler implements a jump table for cases used in switch.

4: It is not necessary to use a break in every switch statement.

A. 1,2 B. 1,3,4

C. 2,4 D. 2

1. 

A short integer is at least 16 bits wide and a long integer is at least 32 bits wide.

A. True B. False

2. 

If scanf() is used to store a value in a char variable then along with the value a carriage

return(\r) also gets stored it.

A. True B. False

3. 

The modulus operator cannot be used with a long double.

A. True B. False

4. 

A char variable can store either an ASCII character or a Unicode character.

A. True B. False

View Answer Online Compiler Report Discuss in Forum1. 

The way the break is used to take control out of switch and continue to take control of the beginning of the switch?

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum

2. 

Can we use a switch statement to switch on strings?

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum

3. 

We want to test whether a value lies in the range 2 to 4 or 5 to 7. Can we do this using a switch?

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum

13

Page 14: c Language Object Types

4. 

By default, the data type of a constant without a decimal point is int, whereas the one with a decimal point is a double.

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum1. 

Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?

A. rem = 3.14 % 2.1;

B. rem = modf(3.14, 2.1);

C. rem = fmod(3.14, 2.1);

D. Remainder cannot be obtain in floating point division.

View Answer Online Compiler Report Discuss in Forum

2. 

What are the types of linkages?

A. Internal and External B. External, Internal and None

C. External and None D. Internal

View Answer Online Compiler Report Discuss in Forum

3. 

Which of the following special symbol allowed in a variable name?

A. * (asterisk) B. | (pipeline)

C. - (hyphen) D. _ (underscore)

View Answer Online Compiler Report Discuss in Forum

4.  Is there any difference between following declarations?

1 : extern int fun();

2 : int fun();

A. Both are identical

B. No difference, except extern int fun(); is probably in another file

C. int fun(); is overrided with extern int fun();

D. None of these

View Answer Online Compiler Report Discuss in Forum

5. 

How would you round off a value from 1.66 to 2.0?

A. ceil(1.66) B. floor(1.66)

C. roundup(1.66) D. roundto(1.66)

View Answer Online Compiler Report Discuss in Forum6. 

By default a real number is treated as a

A. float B. double

C. long double D. far double

View Answer Online Compiler Report Discuss in Forum

7.  Which of the following is not user defined data type?

14

Page 15: c Language Object Types

1 :struct book{ char name[10]; float price; int pages;};

2 :long int l = 2.35;

3 :enum day {Sun, Mon, Tue, Wed};

A. 1 B. 2

C. 3 D. Both 1 and 2

View Answer Online Compiler Report Discuss in Forum

8. 

Is the following statement a declaration or definition?extern int i;

A. Declaration B. Definition

C. Function D. Error

View Answer Online Compiler Report Discuss in Forum

9.  Identify which of the following are declarations

1 : extern int x;

2 : float square ( float x ) { ... }

3 : double pow(double, double);

A. 1 B. 2

C. 1 and 3 D. 3

View Answer Online Compiler Report Discuss in Forum

10.  In the following program where is the variable a getting defined and where it is getting

declared?

#include<stdio.h>int main(){ extern int a; printf("%d\n", a); return 0;}int a=20;

A. extern int a is declaration, int a = 20 is the definition

B. int a = 20 is declaration, extern int a is the definition

C. int a = 20 is definition, a is not defined

D. a is declared, a is not defined

View Answer Online Compiler Report Discuss in ForumWhen we mention the prototype of a function?

A. Defining B. Declaring

C. Prototyping D. Calling

View Answer Online Compiler Report Discuss in Forum1. 

What are the different types of real data type in C ?

15

Page 16: c Language Object Types

A. float, double B. short int, double, long int

C. float, double, long double D. double, long int, float

View Answer Online Compiler Report Discuss in Forum

2. 

What will you do to treat the constant 3.14 as a long double?

A. use 3.14LD B. use 3.14L

C. use 3.14DL D. use 3.14LF

View Answer Online Compiler Report Discuss in Forum

3.  If the binary eauivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what will be the output of the program (on intel machine)?

#include<stdio.h>#include<math.h>int main(){ float a=5.375; char *p; int i; p = (char*)&a; for(i=0; i<=3; i++) printf("%02x\n", (unsigned char)p[i]); return 0;}

A. 40 AC 00 00 B. 04 CA 00 00

C. 00 00 AC 40 D. 00 00 CA 04

View Answer Online Compiler Report Discuss in Forum

4. 

Which of the following range is a valid long double ?

A. 3.4E-4932 to 1.1E+4932 B. 3.4E-4932 to 3.4E+4932

C. 1.1E-4932 to 1.1E+4932 D. 1.7E-4932 to 1.7E+4932

View Answer Online Compiler Report Discuss in Forum

5.  Which statement will you add in the following program to work it correctly?

#include<stdio.h>int main(){ printf("%f\n", log(36.0)); return 0;}

A. #include<conio.h> B. #include<math.h>

C. #include<stdlib.h> D. #include<dos.h>

View Answer Online Compiler Report Discuss in Forum

6. 

We want to round off x, a float, to an int value, The correct way to do is

A. y = (int)(x + 0.5) B. y = int(x + 0.5)

C. y = (int)x + 0.5 D. y = (int)((int)x + 0.5)

View Answer Online Compiler Report Discuss in Forum

7. 

The binary equivalent of 5.375 is

16

Page 17: c Language Object Types

A. 101.101110111 B. 101.011

C. 101011 D. None of above

View Answer Online Compiler Report Discuss in Forum

8. 

A float occupies 4 bytes. If the hexadecimal equivalent of these 4 bytes are A, B, C and D, then when this float is stored in memory in which of the following order do these

bytes gets stored?

A. ABCD

B. DCBA

C. 0xABCD

D. Depends on big endian or little endian architecture

View Answer Online Compiler Report Discuss in Forum

9. 

What will you do to treat the constant 3.14 as a float?

A. use float(3.14f) B. use 3.14f

C. use f(3.14) D. use (f)(3.14)

View Answer Online Compiler Report Discuss in Forum

10. 

Which of the following statement obtains the remainder on dividing 5.5 by 1.3 ?

A. rem = (5.5 % 1.3) B. rem = modf(5.5, 1.3)

C. rem = fmod(5.5, 1.3) D. Error: we can't divide

View Answer Online Compiler Report Discuss in Forum1.  What will be the output of the program?

#include<stdio.h>int main(){ float a=0.7; if(a < 0.7) printf("C\n"); else printf("C++\n"); return 0;}

A. C B. C++

C. Compiler error D. Non of above

View Answer Online Compiler Report Discuss in Forum

2.  What will be the output of the program?

#include<stdio.h>int main(){ float *p; printf("%d\n", sizeof(p)); return 0;}

A. 2 in 16bit compiler, 4 in 32bit compiler

B. 4 in 16bit compiler, 2 in 32bit compiler

17

Page 18: c Language Object Types

C. 4 in 16bit compiler, 4 in 32bit compiler

D. 2 in 16bit compiler, 2 in 32bit compiler

View Answer Online Compiler Report Discuss in Forum

3.  What will be the output of the program?

#include<stdio.h>int main(){ float fval=7.29; printf("%d\n", (int)fval); return 0;}

A. 0 B. 0.0

C. 7.0 D. 7

View Answer Online Compiler Report Discuss in Forum

4.  What will be the output of the program?

#include<stdio.h>#include<math.h>int main(){ printf("%f\n", sqrt(36.0)); return 0;}

A. 6.0 B. 6

C. 6.000000 D. Error: Prototype sqrt() not found.

View Answer Online Compiler Report Discuss in Forum

5.  What will be the output of the program?

#include<stdio.h>#include<math.h>int main(){ printf("%d, %d, %d\n", sizeof(3.14f), sizeof(3.14), sizeof(3.14l)); return 0;}

A. 4, 4, 4 B. 4, 8, 8

C. 4, 8, 10 D. 4, 8, 12

View Answer Online Compiler Report Discuss in Forum6.  What will be the output of the program?

#include<stdio.h>int main(){ float f=43.20; printf("%e, ", f); printf("%f, ", f); printf("%g", f); return 0;}

A. 4.320000e+01, 43.200001, 43.2 B. 4.3, 43.22, 43.21

C. 4.3e, 43.20f, 43.00 D. Error

View Answer Online Compiler Report Discuss in Forum

7.  What will be the output of the program?

18

Page 19: c Language Object Types

#include<stdio.h>int main(){ float a=0.7; if(a < 0.7f) printf("C\n"); else printf("C++\n"); return 0;}

A. C B. C++

C. Compiler error D. Non of above

View Answer Online Compiler Report Discuss in Forum

8.  What will be the output of the program?

#include<stdio.h>#include<math.h>int main(){ float n=1.54; printf("%f, %f\n", ceil(n), floor(n)); return 0;}

A. 2.000000, 1.000000 B. 1.500000, 1.500000

C. 1.550000, 2.000000 D. 1.000000, 2.000000

View Answer Online Compiler Report Discuss in Forum

9.  What will be the output of the program?

#include<stdio.h>int main(){ float d=2.25; printf("%e,", d); printf("%f,", d); printf("%g,", d); printf("%lf", d); return 0;}

A. 2.2, 2.50, 2.50, 2.5

B. 2.2e, 2.25f, 2.00, 2.25

C. 2.250000e+000, 2.250000, 2.25, 2.250000

D. Error

View Answer Online Compiler Report Discuss in Forum1. 

In which numbering system can the binary number 1011011111000101 be easily

converted to?

A. Decimal system B. Hexadecimal system

C. Octal system D. No need to convert

View Answer Online Compiler Report Discuss in Forum

2. 

Which bitwise operator is suitable for turning off a particular bit in a number?

A. && operator B. & operator

19

Page 20: c Language Object Types

C. || operator D. ! operator

View Answer Online Compiler Report Discuss in Forum

3. 

Which bitwise operator is suitable for turning on a particular bit in a number?

A. && operator B. & operator

C. || operator D. | operator

View Answer Online Compiler Report Discuss in Forum

4. 

Which bitwise operator is suitable for checking whether a particular bit is on or off?

A. && operator B. & operator

C. || operator D. ! operator

View Answer Online Compiler Report Discuss in Forum1.  Assunming, integer is 2 byte, What will be the output of the program?

#include<stdio.h>

int main(){ printf("%x\n", -1>>1); return 0;}

A. ffff B. 0fff

C. 0000 D. fff0

View Answer Online Compiler Report Discuss in Forum

2.  If an unsigned int is 2 bytes wide then, What will be the output of the program ?

#include<stdio.h>

int main(){ unsigned int m = 32; printf("%x\n", ~m); return 0;}

A. ffff B. 0000

C. ffdf D. ddfd

View Answer Online Compiler Report Discuss in Forum

3.  Assuming a integer 2-bytes, What will be the output of the program?

#include<stdio.h>

int main(){ printf("%x\n", -1<<3); return 0;}

A. ffff B. fff8

C. 0  D. -1

View Answer Online Compiler Report Discuss in Forum

4.  If an unsigned int is 2 bytes wide then, What will be the output of the program ?

20

Page 21: c Language Object Types

#include<stdio.h>

int main(){ unsigned int a=0xffff; ~a; printf("%x\n", a); return 0;}

A. ffff B. 0000

C. 00ff D. ddfd

View Answer Online Compiler Report Discuss in Forum

5.  What will be the output of the program?

#include<stdio.h>

int main(){ unsigned char i = 0x80; printf("%d\n", i<<1); return 0;}

A. 0 B. 256

C. 100 D. 80

View Answer Online Compiler Report Discuss in Forum6.  What will be the output of the program?

#include<stdio.h>

int main(){ printf("%d >> %d %d >> %d\n", 4 >> 1, 8 >> 1); return 0;}

A. 4 1 8 1

B. 4 >> 1 8 >> 1

C. 2 >> 4 Garbage value >> Garbage value

D. 2 4

View Answer Online Compiler Report Discuss in Forum

7.  What will be the output of the program?

#include<stdio.h>

int main(){ char c=48; int i, mask=01; for(i=1; i<=5; i++) { printf("%c", c|mask); mask = mask<<1; } return 0;}

A. 12400 B. 12480

C. 12500 D. 12556

View Answer Online Compiler Report Discuss in Forum

21

Page 22: c Language Object Types

8.  What will be the output of the program?

#define P printf("%d\n", -1^~0);#define M(P) int main()\ {\ P\ return 0;\ }M(P)

A. 1 B. 0

C. -1 D. 2

View Answer Online Compiler Report Discuss in Forum

9.  What will be the output of the program ?

#include<stdio.h>

int main(){ int i=32, j=0x20, k, l, m; k=i|j; l=i&j; m=k^l; printf("%d, %d, %d, %d, %d\n", i, j, k, l, m); return 0;}

A. 0, 0, 0, 0, 0 B. 0, 32, 32, 32, 32

C. 32, 32, 32, 32, 0 D. 32, 32, 32, 32, 32

View Answer Online Compiler Report Discuss in Forum

10.  What will be the output of the program?

#include<stdio.h>

int main(){ printf("%d %d\n", 32<<1, 32<<0); printf("%d %d\n", 32<<-1, 32<<-0); printf("%d %d\n", 32>>1, 32>>0); printf("%d %d\n", 32>>-1, 32>>-0); return 0;}

A. Garbage values B.

64 320 3216 320 32

C. All zeros D.

8 00 032 00 16

View Answer Online Compiler Report Discuss in Forum11.  What will be the output of the program?

#include<stdio.h>

int main(){ unsigned int res; res = (64 >>(2+1-2)) & (~(1<<2)); printf("%d\n", res); return 0;}

A. 32 B. 64

22

Page 23: c Language Object Types

C. 0 D. 128

View Answer Online Compiler Report Discuss in Forum

12.  What will be the output of the program ?

#include<stdio.h>

int main(){ int i=4, j=8; printf("%d, %d, %d\n", i|j&j|i, i|j&&j|i, i^j); return 0;}

A. 4, 8, 0 B. 1, 2, 1

C. 12, 1, 12 D. 0, 0, 0

View Answer Online Compiler Report Discuss in Forum1.  Which of the following statements are correct about the program?

#include<stdio.h>

int main(){ unsigned int num; int i; scanf("%u", &num); for(i=0; i<16; i++) { printf("%d", (num<<i & 1<<15)?1:0); } return 0;}

A. It prints all even bits from num

B. It prints all odd bits from num

C. It prints binary equivalent num

D. Error

View Answer Online Compiler Report Discuss in Forum

2.  Which of the following statements are correct about the program?

#include<stdio.h>

int main(){ unsigned int num; int c=0; scanf("%u", &num); for(;num;num>>=1) { if(num & 1) c++; } printf("%d", c); return 0;}

A. It counts the number of bits that are ON (1) in the number num.

B. It counts the number of bits that are OFF (0) in the number num.

C. It sets all bits in the number num to 1

D. Error

View Answer Online Compiler Report Discuss in Forum

23

Page 24: c Language Object Types

3.  Which of the following statements are correct about the program?

#include<stdio.h>char *fun(unsigned int num, int base);

int main(){ char *s; s=fun(128, 2); s=fun(128, 16); printf("%s\n",s); return 0;}char *fun(unsigned int num, int base){ static char buff[33]; char *ptr = &buff[sizeof(buff)-1]; *ptr = '\0'; do { *--ptr = "0123456789abcdef"[num %base]; num /=base; }while(num!=0); return ptr;}

A. It converts a number to a given base.

B. It converts a number to its equivalent binary.

C. It converts a number to its equivalent hexadecimal.

D. It converts a number to its equivalent octal.

View Answer Online Compiler Report Discuss in Forum

4.  Which of the following statements are correct about the program?

#include<stdio.h>

int main(){ unsigned int m[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; unsigned char n, i; scanf("%d", &n); for(i=0; i<=7; i++) { if(n & m[i]) printf("yes"); } return 0;}

A. It will put OFF all bits that are ON in the number n

B. It will test whether the individual bits of n are ON or OFF

C. It will put ON all bits that are OFF in the number n

D. It will report compilation errors in the if statement.

View Answer Online Compiler Report Discuss in Forum1. 

Left shifting a number by 1 is always equivalent to multiplying it by 2.

A. True B. False

View Answer Online Compiler Report Discuss in Forum

2. 

In the statement expression1 >> expression2. if expression1 is a signed integer

with its leftmost bit set to 1 then on right shifting it the result of the statement will vary from computer to computer

A. True B. False

View Answer Online Compiler Report Discuss in Forum

24

Page 25: c Language Object Types

3. 

Bitwise & and | are unary operators

A. True B. False

View Answer Online Compiler Report Discuss in Forum

4. 

Bitwise & can be used to check if more than one bit in a number is on.

A. True B. False

View Answer Online Compiler Report Discuss in Forum

5. 

Bitwise & can be used to check if a bit in number is set or not.

A. True B. False

View Answer Online Compiler Report Discuss in Forum6. 

Bitwise & can be used to divide a number by powers of 2

A. True B. False

View Answer Online Compiler Report Discuss in Forum

7. 

Left shifting an unsigned int or char by 1 is always equivalent to multiplying it by 2.

A. True B. False

View Answer Online Compiler Report Discuss in Forum

8. 

On left shifting, the bits from the left are rotated and brought to the right and accommodated where there is empty space on the right?

A. True B. False

View Answer Online Compiler Report Discuss in Forum1. 

Bitwise & can be used in conjunction with ~ operator to turn off 1 or more bits in a number.

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum

2. 

Bitwise can be used to reverse a sign of a number.

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum

3. 

Bitwise can be used to generate a random number.

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum

4. 

Bitwise | can be used to multiply a number by powers of 2.

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum

5. 

Bitwise | can be used to set multiple bits in number.

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum

25

Page 26: c Language Object Types

6. 

Bitwise can be used to perform addition and subtraction.

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum

7. 

Bitwise | can be used to set a bit in number.

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum1. 

Which of the following is the correct order of evaluation for the below expression?z = x + y * z / 4 % 2 - 1

A. * / % + - = B. = * / % + -

C. / * % - + = D. * % / - + =

View Answer Online Compiler Report Discuss in Forum

2. 

Which of the following correctly shows the hierarchy of arithmetic operations in C?

A. / + * - B. * - / +

C. + - / * D. / * + -

View Answer Online Compiler Report Discuss in Forum

3. 

Which of the following is the correct usage of conditional operators used in C?

A. a>b ? c=30 : c=40; B. a>b ? c=30;

C. max = a>b ? a>c?a:c:b>c?b:c D. return (a>b)?(a:b)

View Answer Online Compiler Report Discuss in Forum

4. 

Which of the following is the correct order if calling functions in the below code?a = f1(23, 14) * f2(12/4) + f3();

A. f1, f2, f3

B. f3, f2, f1

C. Order may vary from compiler to compiler

D. None of above

View Answer Online Compiler Report Discuss in Forum

5.  Which of the following are unary operators in C?

1. !

2. sizeof

3. ~

4. &&

A. 1, 2 B. 1, 3

C. 2, 4 D. 1, 2, 3

View Answer Online Compiler Report Discuss in ForumIn which order do the following gets evaluated

1. Relational

2. Arithmetic

3. Logical

26

Page 27: c Language Object Types

4. Assignment

A. 2134 B. 1234

C. 4321 D. 3214

View Answer Online Compiler Report Discuss in Forum1.  What will be the output of the program?

#include<stdio.h>int main(){ int i=-3, j=2, k=0, m; m = ++i && ++j && ++k; printf("%d, %d, %d, %d\n", i, j, k, m); return 0;}

A. -2, 3, 1, 1 B. 2, 3, 1, 2

C. 1, 2, 3, 1 D. 3, 3, 1, 2

View Answer Online Compiler Report Discuss in Forum

2.  Assunming, integer is 2 byte, What will be the output of the program?

#include<stdio.h>

int main(){ printf("%x\n", -2<<2); return 0;}

A. ffff B. 0  

C. fff8 D. Error

View Answer Online Compiler Report Discuss in Forum

3.  What will be the output of the program?

#include<stdio.h>int main(){ int i=-3, j=2, k=0, m; m = ++i || ++j && ++k; printf("%d, %d, %d, %d\n", i, j, k, m); return 0;}

A. 2, 2, 0, 1 B. 1, 2, 1, 0

C. -2, 2, 0, 0 D. -2, 2, 0, 1

View Answer Online Compiler Report Discuss in Forum

4.  What will be the output of the program?

#include<stdio.h>int main(){ int x=12, y=7, z; z = x!=4 || y == 2; printf("z=%d\n", z); return 0;}

A. z=0 B. z=1

C. z=4 D. z=2

View Answer Online Compiler Report Discuss in Forum

27

Page 28: c Language Object Types

5.  What will be the output of the program?

#include<stdio.h>int main(){ static int a[20]; int i = 0; a[i] = i ; printf("%d, %d, %d\n", a[0], a[1], i); return 0;}

A. 1, 0, 1 B. 1, 1, 1

C. 0, 0, 0 D. 0, 1, 0

View Answer Online Compiler Report Discuss in Forum6.  What will be the output of the program?

#include<stdio.h>int main(){ int i=4, j=-1, k=0, w, x, y, z; w = i || j || k; x = i && j && k; y = i || j &&k; z = i && j || k; printf("%d, %d, %d, %d\n", w, x, y, z); return 0;}

A. 1, 1, 1, 1 B. 1, 1, 0, 1

C. 1, 0, 0, 1 D. 1, 0, 1, 1

View Answer Online Compiler Report Discuss in Forum

7.  What will be the output of the program?

#include<stdio.h>int main(){ int i=-3, j=2, k=0, m; m = ++i && ++j || ++k; printf("%d, %d, %d, %d\n", i, j, k, m); return 0;}

A. 1, 2, 0, 1 B. -3, 2, 0, 1

C. -2, 3, 0, 1 D. 2, 3, 1, 1

View Answer Online Compiler Report Discuss in Forum

8.  What will be the output of the program?

#include<stdio.h>int main(){ int x=4, y, z; y = --x; z = x--; printf("%d, %d, %d\n", x, y, z); return 0;}

A. 4, 3, 3 B. 4, 3, 2

C. 3, 3, 2 D. 2, 3, 3

View Answer Online Compiler Report Discuss in Forum

9.  What will be the output of the program?

28

Page 29: c Language Object Types

#include<stdio.h>int main(){ int i=3; i = i++; printf("%d\n", i); return 0;}

A. 3 B. 4

C. 5 D. 6

View Answer Online Compiler Report Discuss in Forum

10.  What will be the output of the program?

#include<stdio.h>int main(){ int a=100, b=200, c; c = (a == 100 || b > 200); printf("c=%d\n", c); return 0;}

A. c=100 B. c=200

C. c=1 D. c=300

View Answer Online Compiler Report Discuss in Forum11.  What will be the output of the program?

#include<stdio.h>int main(){ int x=55; printf("%d, %d, %d\n", x<=55, x=40, x>=10); return 0;}

A. 1, 40, 1 B. 1, 55, 1

C. 1, 55, 0 D. 1, 1, 1

View Answer Online Compiler Report Discuss in Forum

12.  What will be the output of the program?

#include<stdio.h>int main(){ int i=2; printf("%d, %d\n", ++i, ++i); return 0;}

A. 3, 4

B. 4, 3

C. 4, 4

D. Output may vary from compiler to compiler

View Answer Online Compiler Report Discuss in Forum

13.  What will be the output of the program?

29

Page 30: c Language Object Types

#include<stdio.h>int main(){ int k, num=30; k = (num>5 ? (num <=10 ? 100 : 200): 500); printf("%d\n", num); return 0;}

A. 200 B. 30

C. 100 D. 500

View Answer Online Compiler Report Discuss in Forum

14.  What will be the output of the program?

#include<stdio.h>int main(){ char ch; ch = 'A'; printf("The letter is"); printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'a' - 'A':ch); printf("Now the letter is"); printf("%c\n", ch >= 'A' && ch <= 'Z' ? ch : ch + 'a' - 'A'); return 0;}

A.The letter is aNow the letter is A

B.The letter is ANow the letter is a

C. Error D. None of above

View Answer Online Compiler Report Discuss in Forum

15.  What will be the output of the program?

#include<stdio.h>int main(){ int i=2; int j = i + (1, 2, 3, 4, 5); printf("%d\n", j); return 0;}

A. 4 B. 7

C. 6 D. 5

View Answer Online Compiler Report Discuss in Forum1. 

Associativity has no role to play unless the precedence of operator is same.

A. True B. False

View Answer Online Compiler Report Discuss in Forum

2. 

The expression of the right hand side of || operators doesn't get evaluated if the left hand

side determines the outcome.

A. True B. False

View Answer Online Compiler Report Discuss in Forum

3. 

In the expression a=b=5 the order of Assignment is NOT decided by Associativity of

operators

A. True B. False

View Answer Online Compiler Report Discuss in Forum

30

Page 31: c Language Object Types

4. 

Associativity of an operator is either Left to Right or Right to Left.

A. True B. False

View Answer Online Compiler Report Discuss in Forum1.  Are the following two statement same?

1. a <= 20 ? b = 30: c = 30;

2. (a <=20) ? b : c = 30;

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum

2. 

Two different operators would always have different Associativity.

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum

3. 

Will the expression *p = p be disallowed by the compiler?

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum

4. 

Every operator has an Associativity

A. Yes B. No

View Answer Online Compiler Report Discuss in Forum

31