C++ MCQ

63
C++ 1. When the compiler cannot differentiate between two overloaded constructors, they are called A. overloaded B. Destructed C. ambiguous D. Dubious Option : C 2. Adding a derived class to a base class requires fundamental changes to the base class A. True B. False Option B 3. To expose a data member to the rest of the program, you must declare the data member in the _____ section of the class A. Common B. Exposed C. Public D. Unrestricted E. User Option C 4. A default catch block catches A. all thrown objects B . no thrown objects C . any thrown object that has not been caught by an earlier catch block

description

A set of C++ multiple choice questions helpful to check your competence in the programming language

Transcript of C++ MCQ

Page 1: C++ MCQ

C++

1.

When the compiler cannot differentiate between two overloaded constructors, they are called

A. overloaded B. Destructed

C. ambiguous D. Dubious

Option : C

2.

Adding a derived class to a base class requires fundamental changes to the base class

A. True B. False

Option B

3.

To expose a data member to the rest of the program, you must declare the data member in the _____ section of the class

A. Common B. Exposed

C. Public D. Unrestricted

E. User

Option C

4. A default catch block catches

A. all thrown objects

B. no thrown objects

C. any thrown object that has not been caught by an earlier catch block

D. all thrown objects that have been caught by an earlier catch block

Option : C

5.

Page 2: C++ MCQ

If you design a class that needs special initialization tasks, you will want to design a(n) _____

A. housekeeping routine

B. Initialize

C. Constructor

D. Compiler

Option C

6.

Which of the following statements is false?

A. A function is a block of code that performs a specific task

B.Functions allow programmers to break large and complex problems into small and manageable tasks

C. Functions allow programmers to use existing code to perform common tasks

D. Functions can be called, or invoked, only once in a program

E. Programmer-defined functions can be either value-returning or void

Option D

7.

The generic type in a template function

A. must be T

B. can be T

C. cannot be T for functions you create, but may be for C++'s built-in functions

D. cannot be T

Page 3: C++ MCQ

Option B

8.

When a child class function is called, the compiler looks first for a matching function name in the _____

A. class of the object using the function name

B. immediate ancestor class

C. base class

D. descendant class

Option A

9.

A function that is called automatically each time an object is destroyed is a

A. Constructor B. Destructor

C. Destroyer D. Terminator

 Option B

10.

If you create an instantiation of a class template with an int, and then create a second instantiation with a double, then

A. you must precede each function call with the word int or double

B. once a function is used as one type, it becomes unavailable for use with the other type

C. there is no difference in the procedure to call a member function

D. you cannot perform this operation in C++

Page 4: C++ MCQ

Option A

Page 5: C++ MCQ

11.

Overloaded functions are required to

A. have the same return type

B. have the same number of parameters

C. perform the same basic functions

D. None of the above

Option D

12.

C++ allows you to define the same functions more than once in the same program _____

A. if the definitions are identical

B. if the definitions are included in two separate #include files

C. if the definitions are located in a single #include file that is included more than once

D.C++ does not allow you to define the same functions more than once in the same program

Option D

13.

When you create a derived class and instantiate an object _____

A. the parent class object must be constructed first

B. the child class object must be constructed first

C. the parent class object must not be constructed

D. the child class object must not be constructed

 Option A

Page 6: C++ MCQ

14.

A function in a derived class that has the same name as a function in the parent class

A. will override the base class function

B. will cause an error message to display

C. will be overridden by the base class function

D. will execute immediately often the base class function executes

 Option A

15.

To hide a data member from the program, you must declare the data member in the _____ section of the class

A. concealed B. Confidential

C. hidden D. Private

E. restricted

Option D

16.

You may override the class access specifier for_____

A. public members

B. public and protected members

C. any specific class members you choose

D. no clas smembers

Option C

Page 7: C++ MCQ

17.

Assume that your version of C++ can recognize only the first 8 characters of an identifier name, through identifier names may be arbitrarily long. Which of the following identifier names is not distinct:

A. list, list2

B. address, Address

C. identifier_l, identifier_2

D. answer, ANSWER

E. None of the above

Option C

18.

When you define an object that is a member of a class, such as Student Abby; _____

A. a block of memory is set aside and all data members are assigned valid values

B. a block of memory is set aside

C. no memory is set aside until values are defined

D. no memory is set aside, but valid values are assigned to data members

Option B

19.

An advantage of using local variables is that _____

A. they are known to all functions in the file

B.names used in one function do not affect data stored in variables with the same names in other functions

Page 8: C++ MCQ

C. values given to local variables are retained when those parameters go out of scope

D. the program does not become "crowded" with too many variable names

Option D

20.

The difference between a return and a throw is that _____

A. with a throw, no value can be sent

B. with a return, no value can be sent

C. with a throw, execution takes place at the location from which the function was called

D. with a return, execution takes place at the location from which the function was called

Option D

21.

You typically initialize a String variable to _____

A. an asterisk

B. a space enclosed in single quotes

C. the number 0

D. a zero-length string

Option D

22.

The prototype for a derived class constructor may include arguments for

A. data members of the derived class

Page 9: C++ MCQ

B. data members of the base class

C. both (a) and (b)

D. neither (a) nor (b)

 Option C

Page 10: C++ MCQ

23.

You___________overload function templates

A. may, as long as each version has the same arguments

B. may, as long as each version has different arguments

C. Must

D. must not

Option B

24.

A member function uses the correct object when you call it because

A. a copy of the object is passed to the function

B. the address of the object is passed to the function

C. the address of the function is passed to another function

D. the address of the object is returned from the function

Option B

25.

Function templates _____________

A. must have exactly one parameter

B. may have more than one parameter as long as they are of the same type

C. may have more than one parameter of any type

D. may not have parameters

Option C

Page 11: C++ MCQ
Page 12: C++ MCQ

26.

Private data can be accessed by

A. class member functions

B. functions in derived classes

C. both (a) and (b)

D. neither (a) nor (b)

Option A

27.

When a function performs tasks based on a decision, it has _____

A. functional cohesion

B. coincidental cohesion

C. logical cohesion

D. no cohesion

Option C

28,

To create a template class, you begin with _________

A. the template definition

B. the keyword class

C. the function definitions

D. the keyword definition

Option A

Page 13: C++ MCQ
Page 14: C++ MCQ

29.

When the compiler places a copy of a small function's statements directly into a program, the function is said to be _____

A. overloaded B. Mangled

C. inline D. Redundant

Option C

30.

A function stub typically contains

A. the function header

B. the function braces

C. the return statement, if it's value- returning function

D. a display message

E. All of the above

Option E

31.

_____ variables are declared outside of any statement block

A. Area B. Global

C. Local D. Reference

E. Value

Option B

Page 15: C++ MCQ

32.

If you omit any constructor argument when you instantiate an object, you must use default values

A. for all parameters to the constructor

B. for all parameters to the right of the argument

C. for all parameters to the left of the argument

D. for no other parameters

Option B

33.

Code that has already been tested is said to be _____

A. inherited B. Reusable

C. reliable D. Polymorphic

Option C

34.

A class D can be derived from a class C, which is derived from a class B, which is derived from a class A

A. True B. False

Option A

35.

A function that is called automatically each time an object is destroyed is a

Page 16: C++ MCQ

A. constructor B. Destructor

C. destroyer D. Terminator

Option B

Page 17: C++ MCQ

36.

We can output text to an object of class ofstream using the insertion operator « because

A. the ofstream class is a stream

B. the insertion operator works with all classes

C. we are actually outputting to cout

D. the insertion operator is overloaded in ofstream

Option D

37.

he operator that allocates new memory is _____

A. Allocate

B. Mem

C. New

D. Next

Option C

38.

Which is a good guideline for creating function names?

A. Use all lowercase letters to identify the functions as C++ functions

B. Use long names to reduce the likelihood of creating a duplicate function name

C. Use abbreviations as much as possible to save both keystrokes and memory

D. Avoid the use of digits because they are easily confused with letters

Page 18: C++ MCQ

Option D

Page 19: C++ MCQ

39.

Reserving memory during program execution is known as reserving it

A. dynamically B. Statically

C. functionally D. Powerfully

 Option A

40.

When you write to a file rather than the screen, you use the C++ class _____

A. iostream B. Filed

C. fstream D. Diskclass

Option C

41.

A function whose purpose is to send messages to other functions is known as a _____

A. dispatcher B. Courier

C. messenger D. Sender

Option A

42.

The type of value that a function sends back to the function that calls it is known as its _____

A. Type

Page 20: C++ MCQ

B. return value

C. reference data

D. Sentinel

Option B

Page 21: C++ MCQ

43.

Which of the following are never inherited?

A. public data members

B. constructor functions

C. void functions

D. overloaded + operators

Option B

44.

In a template function, _____ argument is generic, or parameterized

A. No

B. exactly one

C. at least one

D. more than one

Option C

45.

Assume that a program creates and initializes a Short Integer variable named age and a pointer named agePtr, to which it assigns the address of the age variable. Which of the following statements will assign the number 21 to the age variable?

A. age = 21;

B. *age = 21;

C. agePtr = 21;

D. *agePtr = 21;

E. both (a) and (d)

Page 22: C++ MCQ

 Option E

Page 23: C++ MCQ

46.

The statement fwrite ( (char*)&objl, sizeof(objl) );

A. writes the member functions of objl to fl

B. writes the data in objl to fl

C. writes the member functions and me data of obj 1 to fl

D. writes the address of objl to fl

Option B

47.

The loosest type of coupling is

A. data coupling

B. control coupling

C. external coupling

D. pathological coupling

Option A

48.

The main() function is always

A. a called function

B. a calling function

C. recursive function

D. used at the end of the program

E. None of the above

Page 24: C++ MCQ

Option B

Page 25: C++ MCQ

49.

The weakest form of cohesion is

A. coincidental B. Functional

C. logical D. Communicational

Option A

50.

If the description of function is "input the quantity, validate that the quantity is greater than 1, subtract 1 from the quantity, and print the quantity," the function is

A. sequentially cohesive

B. logically cohesive

C. communicationally cohesive

D. functionally cohesive

Option B

51.

A function that changes an object's state belongs to the category of

A. inspector functions

B. mutator functions

C. auxiliary functions

D. manager functions

Option B

Page 26: C++ MCQ

52.

When you create a derived class and instantiate on object

A. the parent class object must be constructed first

B. the child class object must be constructed first

C. the parent class object must not be constructed

D. the child class object must not be constructed

Option A

53.

If you want to override constructor default values for an object you are instantiating, you must also override

A. all other parameters to that constructor

B. all parameters to the left of that value

C. all parameters to the right of that value

D. no other parameters to that constructor

 Option B

54.

The return type for all destructors is

A. the class

B. Void

C. the same as the first data in the class

D. None

Page 27: C++ MCQ

Option D

Page 28: C++ MCQ

55.

When a program calls a function that has default parameters, if you omit an argument, you must _____

A. not omit any other arguments

B. omit all arguments

C. omit all arguments to the right of that argument

D. omit all arguments to the left of that argument

Option C

56. Function overloading in C++ is

a. a group function with the same nameb. all have the same number and type of argumentsc. functions with same name and same number and type of arguments

Option a

57.

How constructor differ from destructora. constructors can be overloaded but destructors can't be overloadedb. constructors can take arguments but destructor can'tc. both a and b

option c

58.

The program can access the private members of a class

A. Directly

Page 29: C++ MCQ

B. only through other private members of the class

C. only through other public members of the class

D.None of the above - the program cannot access the private members of a class in any way

Option C

59.

The function whose prototype is void getData(Item *thing); receives

A. a pointer to a structure

B. a reference to a structure

C. a copy of a structure

D. Nothing

Option A.

60.

If you want only one memory location to be reserved for a class variable, no matter how many objects are instantiated, you should declare the variable as________

A. dynamic B. Unary

C. static D. Volatile

Option C

C Questions

Page 30: C++ MCQ
Page 31: C++ MCQ

1. On executing the following program how many times would the message “keep it up” would get printed?

#include<stdio.h>void main(){int x;for(x=1;x< =10;x++){if(x<5)continue;elsebreak;printf(“keep it up”);}}

Choices:A. Infinite timesB. 11 timesC. 0 timesD. OnceE. 10 times

Solution:

C

2. Which of the following is the correct output for the program given below?#include<stdio.h>void main(){int i=1;switch(i);{printf(“Hello”);case 1:printf(“\n Hi”);break;case 2:printf(“\n Bye”);break;}}Choices:

Page 32: C++ MCQ

A. HelloHi

B. Hello Bye

C. HiD. ByeE. Hello

HiBye

Solution:

C

3. Which of the following is the correct output for the program given below?#include<stdio.h>void main(){int i=5;while(i-->=0)printf(“%d”,i);i=5;printf(“\n”);while(i -->=0)printf(“%d”,i);}

Choices:A. 4 3 2 1 0 -1

4 3 2 1 0 -1B. 5 4 3 2 1 0

5 4 3 2 1 0C. ErrorD. 5 4 3 2 1 0

5 4 3 2 1 05 4 3 2 1 0

Solution:A

4. Which of the following is the correct output for the program given below?#include<stdio.h>void main()

{unsigned int i=65535;//assume a 2 byte integer

Page 33: C++ MCQ

while(i++!=0)printf(“%d”,++i);}Choices:Choices:A. Infinite loopB. 0 1 2 ..... 65535C. 1 2 .....32767 -32766 -32765 .... -1 0D. No output

Solution:

A

5. Which of the following statements are correct about the program given below?#include <stdio.h>void main(){int i=0;i++;if(i< =5);{printf(“adds wings to your thoughts”);exit();main();}}Choices:

A. The program prints “adds wings to your thoughts” five times.B. The program prints “adds wings to your thoughts” infinite times.C. The program prints “adds wings to your thoughts” once.D. The call to main() after exit doesn’t materialize.E. The compiler reports on error since main() cannot call itself.

Solution:C and D

Arrays and Pointers:6. Which of the following is the correct output for the program given below?#include <stdio.h>void main(){

int arr[1]={10};printf(“%d”, 0[arr]);

Page 34: C++ MCQ

}Choices:A. 1B. 1C. 0D. None of the above

Solution:

B

7 . Which of the following is the correct output for the program given below?

#include <stdio.h>void main(){float a[]={12.4,2.3,4.5,6.7};printf(“\n%d”, sizeof(a)/sizeof(a[0]));}

Choices:A. 8 B. 16C. 4D. 1Solution:C

8. Which of the following is the correct output for the program given below?

#include <stdio.h>void main(){

static int arr[] = [0,1,2,3,4};

int *p[]={arr,arr+1;arr+2;arr+3;arr+4};

int **ptr=p;

ptr++;

printf(“\n%d%d%d”,ptr-p,*ptr-arr,**ptr);

*ptr++;

Page 35: C++ MCQ

printf(“\n%d%d%d”,ptr-p,*ptr-arr,**ptr);

*++ptr;

printf(“\n%d%d%d”,ptr-p,*ptr-arr,**ptr);

++*ptr;

printf(“\n%d%d%d”,ptr-p,*ptr-arr,**ptr);

printf(“\n%d%d%d”,ptr-p,*ptr-arr,**ptr);

}

Choices:

A. 0 0 01 1 12 2 23 3 3

B. 1 1 22 2 33 3 44 4 1

C. 1 1 12 2 2 3 3 3 3 4 4

D. 0 1 21 2 3 2 3 43 4 Garbage

Solution:C

9. Which of the following is the correct output for the program given below?#include <stdio.h>void main(){static int a[2][2]={1,2,3,4};int i,j;static int *p[]={int *)a,(int *)a+1,(int*)a+2;for(i=0;i<2;i++){for(j=0;j<2;j++)printf(“%d%d%d%d\n”,

Page 36: C++ MCQ

*(*(p+i)+j);*(*(j+p)+i);*(*(i+p)+j);*(*(p+j)+i);}}Choices:

A. 1 1 1 12 3 2 33 2 3 24 4 4 4

B . 1 2 1 22 3 2 3 3 4 3 44 2 4 2

C. 1 1 1 1

2 2 2 2

3 3 3 3

4 4 4 4

D. 1 2 3 4

2 3 4 1

3 4 1 2

4 1 2 3

Solution:

A

10 .Which of the following is the correct output for the program given below?

#include <stdio.h>void main(){Int arr[2] [2] [2] ={10,2,3,4,5,6,7,8};Int *p,*q;P=&arr[1][1][1];

Page 37: C++ MCQ

*q=***arr;Printf(“%d%d”,*p,*q);}

Choices:A. 8 10B. 10 2C. 8 1 D. Garbage values

Solution:

A

11 .Which of the following is the correct output for the program given below?

#include <stdio.h>void main(){void *vp;char ch = 74, *cp=”JACK”;int j=65;vp = &ch;printf(“%c”,*(char*)vp);vp=&j;printf(“%c”,*(int*)vp);vp=cp;printf(“%s”,(char*)vp+2);}

Choices:A. JCKB. J65KC. JAKD. JACK

Solution:D

12 . Which of the following is the correct output for the program given below?

#include <stdio.h>void main(){

Static char *s[]={“black”,”white”,”pink”,”violet”};Char **ptr[]={s+3,s+2,s+1,s},***p;

Page 38: C++ MCQ

P=ptr;++p;Printf(“%s”,**p+1);}

Choices:A. InkB. AckC. IteD. Let

Solution:A

13. Which of the following is the correct output for the program given below?

#include <stdio.h>Fun(void *p);Int i;void main(){

Void *vptr;Vptr=&i;Fun(vptr);}Fun(void *p){Int **q;Q=(int**)&p;Printf(“%d”,**q);}Choices:A. Error: Cannot convert from void ** to int**B. Garbage valueC. 0 D. No output

Solution:C

14. Which of the following is the correct output for the program given below?

#include <stdio.h>void main(){

Page 39: C++ MCQ

Int i,*j,k;I=3;J=&i;Printf(“%d”,i**j*i+j);} Choices:A. 30B. 27C. 9D. 3

Solution:A

15. A pointer to a block of memory is effectively same as an array.A. TrueB. False

Solution:True

Strings:

16. Which of the following is the correct output for the program given below?

#include<stdio.h>#include<string.h>void main(){char str1[20]=”Hello”, str2[2] =”WORLD”;printf(“%s”,strcpy(str2,strcat(str1,str2)));printf(%d”,strlen(str1));}

Choices:A. Hello, 4B. World,9C. Hello World,4D. WorldHello,3

Solution:C

Page 40: C++ MCQ

17.

main(){ int i; clrscr(); printf("%d", &i)+1; scanf("%d", i)-1;}

a. Runtime error.b. Runtime error.  Access violation.c. Compile error.  Illegal syntaxd. None of the above

 

 

 Ans: d, printf( ) prints address/garbage of i,  scanf() dont hav & sign, so scans address for i  +1, -1 dont hav any effect on code

18.

main(int argc, char *argv[]){       (main && argc) ? main(argc-1, NULL) : return 0;}

a. Runtime error.b. Compile error.  Illegal syntaxc. Gets into Infinite loopd. None of the above

 

Ans: b)  illegal syntax for using return

19.main()

Page 41: C++ MCQ

{  int i;  float *pf;  pf = (float *)&i; *pf = 100.00;  printf("\n %d", i);}

a. Runtime error.b. 100c. Some Integer not 100d. None of the above

 

Ans: d) 0

Page 42: C++ MCQ

20.

main(){  int i = 0xff ;  printf("\n%d", i<<2);}

a. 4b. 512c. 1020d. 1024

 

Ans: c) 1020

21.

 #define SQR(x) x * x

main(){  printf("%d", 225/SQR(15));}

a. 1b. 225c. 15d. none of the above

 

Ans: b) 225

22.

union u{  struct st {       int i : 4;       int j : 4;       int k : 4;

Page 43: C++ MCQ

       int l; }st; int i;}u;

main(){    u.i = 100;    printf("%d, %d, %d",u.i, u.st.i, u.st.l);}

a. 4, 4, 0b. 0, 0, 0c. 100, 4, 0d. 40, 4, 0

 

Ans: c) 100, 4, 0

23.union u{     union u    {        int i;        int j;    }a[10];    int b[10];}u;

main(){      printf("\n%d", sizeof(u));      printf("  %d", sizeof(u.a));//      printf("%d", sizeof(u.a[4].i));}

a. 4, 4, 4b. 40, 4, 4c. 1, 100, 1d. 40 400 4

Page 44: C++ MCQ

Ans: 20, 200, error for 3rd printf

24.main(){      int (*functable[2])(char *format, ...) ={printf, scanf};      int i = 100;

      (*functable[0])("%d", i);      (*functable[1])("%d", i);      (*functable[1])("%d", i);      (*functable[0])("%d", &i);

}

a. 100, Runtime error.b. 100, Random number, Random number, Random number.c. Compile errord. 100, Random number

 

25.main(){  int i, j, *p;   i = 25;   j = 100;   p = &i; // Address of i is assigned to pointer p  printf("%f", i/(*p) ); // i is divided by pointer p}

a. Runtime error.b. 1.00000c. Compile errord. 0.00000

 

Ans: c) Error becoz i/(*p) is 25/25 i.e 1 which is int & printed as a float, So abnormal program termination, runs if (float) i/(*p)   -----> Type Casting

Page 45: C++ MCQ

26.main(){       int i, j;       scanf("%d %d"+scanf("%d %d", &i, &j));       printf("%d %d", i, j);}

a. Runtime error.b. 0, 0c. Compile errord. the first two values entered by the user 

Ans: d) two values entered, 3rd will be null pointer assignment

27.

main(){        char *p = "hello world";        p[0] = 'H';        printf("%s", p);}

a. Runtime error.b. “Hello world”c. Compile errord. “hello world”

 

Ans: b) Hello world

28.main(){   char * strA;   char * strB = I am OK;   memcpy( strA, strB, 6);}

Page 46: C++ MCQ

a. Runtime error.b. I am OKc. Compile errord. I am O

 

Ans: c)  I am OK is not in    "   "

30.const int perplexed = 2;#define perplexed 3

main(){    #ifdef perplexed    #undef perplexed    #define perplexed 4    #endif   printf("%d",perplexed);}

a. 0b. 2c. 4d. none of the above

 

Ans: c)

31.struct Foo{  char *pName;};

main(){    struct Foo *obj = malloc(sizeof(struct Foo));    clrscr();    strcpy(obj->pName,"Your Name");    printf("%s", obj->pName);}

Page 47: C++ MCQ

a. Your Nameb. compile errorc. Named. Runtime error

 

Ans a)

32.struct Foo{  char *pName;  char *pAddress;};

main(){    struct Foo *obj = malloc(sizeof(struct Foo));clrscr();    obj->pName = malloc(100);    obj->pAddress = malloc(100);

    strcpy(obj->pName,"Your Name");    strcpy(obj->pAddress, "Your Address");

    free(obj);    printf("%s", obj->pName);    printf("%s", obj->pAddress);}

a. Your Name, Your Addressb. Your Address, Your Addressc. Your Name Your Named. None of the above

 

 

Ans: d) printd Nothing, as after free(obj), no memory is there containing obj->pName   &   pbj->pAddress

Page 48: C++ MCQ

33.main(){      char *a = "Hello ";      char *b = "World";clrscr();      printf("%s", strcat(a,b));}

a. Hellob. Hello Worldc. HelloWorldd. None of the above

 

Ans: b)

34.

main(){      char *a = "Hello ";      char *b = "World";      clrscr();      printf("%s", strcpy(a,b));}

a. “Hello”b. “Hello World”c. “HelloWorld”d. None of the above

 

 

 

Ans: d) World, copies World on a, overwrites Hello in a.

Page 49: C++ MCQ

35.void func1(int (*a)[10]){       printf("Ok it works");}

void func2(int a[][10]){   printf("Will this work?");}  main() {    int a[10][10];          func1(a);    func2(a);}

a. Ok it worksb. Will this work?c. Ok it worksWill this work?d. None of the above

 

 

 

Ans: c)

36.main(){  printf("%d, %d", sizeof('c'), sizeof(100));}

a. 2, 2b. 2, 100c. 4, 100d. 4, 4

 

 

Ans: a) 2, 2

Page 50: C++ MCQ

37.main(){  int i = 100;  clrscr();  printf("%d", sizeof(sizeof(i)));}

a. 2b. 100c. 4d. none of the above

 

Ans: a) 2

38.

main(){  int c = 5;  printf("%d", main||c);}

a. 1b. 5c. 0d. none of the above

 

Ans: a) 1,    if  we use main|c  then error, illegal use of pointer

39.main(){   char c;   int i = 456;   clrscr();   c = i;   printf("%d", c);}

Page 51: C++ MCQ

a. 456b. -456c. random numberd. none of the above

 

 

 

Ans: d) -56

40.

void main (){    int x = 10;    printf ("x = %d, y = %d", x,--x++);}

a. 10, 10b. 10, 9c. 10, 11d. none of the above

 

 

Ans: d) Lvalue required

41.main(){   int i =10, j = 20;   clrscr();   printf("%d, %d, ", j-- , --i);   printf("%d, %d ", j++ , ++i);}

a. 20, 10, 20, 10b. 20, 9, 20, 10

Page 52: C++ MCQ

c. 20, 9, 19, 10d. 19, 9, 20, 10

 

 

 

Ans: c)

42.

main(){  int x=5;  clrscr();

  for(;x==0;x--) {    printf("x=%d\n”", x--);  }}

a. 4, 3, 2, 1, 0b. 1, 2, 3, 4, 5c. 0, 1, 2, 3, 4d. none of the above

 

 

Ans: d) prints nothing, as condition x==0 is False

43.main(){  int x=5;

  for(;x!=0;x--) {    printf("x=%d\n", x--);  }}

a. 5, 4, 3, 2,1b. 4, 3, 2, 1, 0

Page 53: C++ MCQ

c. 5, 3, 1d. none of the above

 

 

 

Ans: d) Infinite loop as x is decremented twice, it never be 0 and loop is going on & on  44main(){  int x=5;  clrscr();

  Fo

r(;x<= 0;x--) {    printf("x=%d ", x--);  }}a. 5,  3, 1b. 5, 2, 1,c. 5, 3, 1, -1, 3d. –3, -1, 1, 3, 5

 

Ans: prints nothing, as condition in loop is false.

Page 54: C++ MCQ

45.main(){   {      unsigned int bit=256;      printf("%d", bit);   }   {      unsigned int bit=512;      printf("%d", bit);   }}

a. 256, 256b. 512, 512c. 256, 512d. Compile error

 

Ans: 256, 512,     becoz these r different blocks, so declaration allowed

46.main(){   int i;   clrscr();   for(i=0;i<5;i++)  {       printf("%d\n",  1L << i);  }}a. 5, 4, 3, 2, 1b. 0, 1, 2, 3, 4c. 0, 1, 2, 4, 8d. 1, 2, 4, 8, 16

 

Ans: d) L does't make any diff.

Page 55: C++ MCQ

47.

48.main(){  signed int bit=512, i=5;

   for(;i;i--)  {       printf("%d\n",  bit >>  (i - (i -1)));  }}

a. 512, 256, 0, 0, 0b. 256, 256, 0, 0, 0c. 512, 512, 512, 512, 512d. 256, 256, 256, 256, 256

 

Ans: d) bit's value is not changed

49.main(){     if (!(1&&0))    {  printf("OK I am done.");    }    else   { printf("OK I am gone.");   }}

a. OK I am doneb. OK I am gonec. compile errord. none of the above

Page 56: C++ MCQ

 

 

Ans: a)

50.main(){   if ((1||0) && (0||1))  {  printf("OK I am done.");    }    else   { printf("OK I am gone.");   }}

a. OK I am doneb. OK I am gonec. compile errord. none of the above

 

 

Ans: a)

51main(){   signed int bit=512, mBit;

  { mBit = ~bit; bit = bit & ~bit ;

 printf("%d %d", bit, mBit);   }}

Page 57: C++ MCQ

a. 0, 0b. 0, 513c. 512, 0d. 0, -513

 

Ans: d)