CBSE - MCQ Question Banks (के. मा. शि. बो . -प्रश्नमाला )

PreviousNext

Q. 189801 Write the syntax of a structure definition.
A. structure.
B. struct.
C. define.
D. tag.

Right Answer is:

SOLUTION

The syntax of a structure definition takes the following form :
struct tag
{
   type variable-name;
   type variable-name;
   type variable-name;
   ...
   ...
} structure-variables;


Q. 189802 What do you understand by a data structure?
A. structure.
B. struct.
C. define.
D. tag.

Right Answer is:

SOLUTION

A data structure is a group of data elements grouped together under one name. Once defined,  a structure becomes a user defined data type. New variables, arrays, even structures can be defined in terms of this data type.  It is treated equivalent to the fundamental data types. Data structure are defined  with keyword ‘struct’, i.e., followed by the tag and the structure members within braces, ending with a semicolon.                           


Q. 189803 We have to store marks of 32 students of english subject. For this purpose we would use an array or structure?
A. structure.
B. struct.
C. define.
D. tag.

Right Answer is:

SOLUTION

We need array to store marks of 32 students. If other details of these students were also being stored we could use an array of structures.    


Q. 189804 Define Call-by-Value.
A. structure.
B. struct.
C. define.
D. tag.

Right Answer is:

SOLUTION

In call-by-value, any changes made to the contents of the structure inside the function to which it is passed do not affect the structure used as an argument.     


Q. 189805 What does # signify in a C++ program?
A. structure.
B. struct.
C. define.
D. tag.

Right Answer is:

SOLUTION

A # sign in the beginning of a statement means it is a preprocessor directive. i.e. the instructions given here will be processed before the program is compiled.                     


Q. 189806 To store employee's details like emp id, salary, designation what should be used array or structure?
A. structure.
B. struct.
C. define.
D. tag.

Right Answer is:

SOLUTION

To store employee's details structure should be used.


Q. 189807 What is a structure?
A. structure.
B. struct.
C. define.
D. tag.

Right Answer is:

SOLUTION

A structure is a group of data elements grouped together under one name. The  keyword ‘struct’ is followed by the tag and the structure members within braces, ending with a semicolon.                           


Q. 189808 Identify errors in the following structure definition-  
                    struct  { int x;
                                   int y;                                     char c;                                 } var1, var2, var3;
A. structure.
B. struct.
C. define.
D. tag.

Right Answer is:

SOLUTION

When tag is missing, only one variable can be declared. Here, three have been declared and this is wrong.         


Q. 189809 Identify errors in the following structure definition-
                struct size{ int length;                                    int breadth;                                     int height;                                 }
A. structure.
B. struct.
C. define.
D. tag.

Right Answer is:

SOLUTION

The structure definition is not terminated properly as the semicolon ';' is missing after the closing brace.           


Q. 189810 When accessing a structure member, what lies to the left of the dot operator?
A. structure.
B. struct.
C. define.
D. tag.

Right Answer is:

SOLUTION

The structure variable.
Example: in T.hour, hour is a structure member to the right of the dot operator. To the left of the dot operator is T, a structure variable.                


Q. 189811 Define a structure to hold time using the 24 hour clock.
A. structure.
B. struct.
C. define.
D. tag.

Right Answer is:

SOLUTION

struct time{ int hour;
                        int min;

                        int sec;

               } ;                         


Q. 189812 What forms the components of a structure?
A. structure.
B. struct.
C. define.
D. tag.

Right Answer is:

SOLUTION

Related data elements that may be stored as variables of different data types form the components of a structure.

 


Q. 189813 Look at the code below –
struct date{ int day;            int mon;            int year;          };                 -------------------                             cout<< D.year << D.mon;               cout<< DT-> day;             The variables being used to access the structure members would have been declared on the -------- line as –
Right Answer is:

SOLUTION

date D, *DT;           


Q. 189814 The statement
#define PI 3.14159
will
 


A. translate one occurence of PI in program to 3.14159.

B. translate two occurences of PI in program to 3.14159.

C. translate one occurence of PI in program to 3.5.

D. translate every occurence of PI in program to 3.14159.

Right Answer is: D

SOLUTION

The #define preprocessor allows us to define symbolic names and constants. #define allows you to make text substitutions before compiling the program.


Q. 189815 When a structure is defined as global, its variables   i.  can be declared in main( ).  ii.  can be declared in any function. iii.  can be passed to any function. iv.  cann't be returned from any function.


A. i & ii.

B. i & iii.

C. ii & iii.

D. i , ii & iii.  

 

Right Answer is: D

SOLUTION

A structure may be local (to a function), if defined within a function. That is, no function other than the one which defines it, can access it (the structure). A structure may be global (to all functions within a program) if defined outside all functions. That is, any function can then access it.


Q. 189816 When a structure is defined within main() , structure variables


A. cannot be accessed  within main( )

B. can be returned by a function

C. can be passed to any function

D. can be accessed only within main( )

Right Answer is: D

SOLUTION

If declared within main() it becomes local to the function main().  


Q. 189817 Which lines have an error in the code below:
# include< iostream.h>
void main()
{
  struct employee
  { 
    char name[25];
    int age;
    int salary;
  };
employee emp;
strcpy(emp.name,"rohan");
emp.age=37;
cout << name;
cout << emp.age;
}


A. emp.age=37;

B. cout << name;

C. strcpy(emp.name,"rohan");

D. employee emp;

Right Answer is: B

SOLUTION

The correct statement is : cout << emp.name;
Once a structure variable has been defined, its members can be accessed through the use of the dot operator. The syntax for accessing a structure element is:
structure-name.element-name  


Q. 189818 The combination having structures within an array is a/an


A. array of structures.

B. nested structure.

C. class of structures.

D. group of structures.
 

Right Answer is: A

SOLUTION

Since an array can contain similar elements, the combination having structures within an array is an array of structures. To declare an array of structures, you must first define a structure and then declare an array variable of that type.


Q. 189819 A preprocessor directive


A. begins with /* and ends with a */ .

B. begins with # and ends with ; .

C. begins with # and ends without ; .

D. begins with { and ends with ); .

Right Answer is: C

SOLUTION

Preprocessor commands are called DIRECTIVES and begin with a pound/hash symbol (#). No white space should appear before the # and a semi colon is NOT required at the end.


Q. 189820 The keyword typedef can be used


A. with any data type.

B. only with fundamental data types.

C. only with user defined data types.

D. only with float data type.

Right Answer is: A

SOLUTION

The keyword typedef does not actually create a new data class, rather it defines a new name for an existing type. The syntax of the typedef statement is
typedef type name;
where type is any C++ datatype and name is the new name for this type.


Q. 189821 A structure can be assigned to another structure if


A. both are of the same type.

B. both have members of the same type.

C. tag was omitted while defining the structure.

D. none of the members are arrays.

Right Answer is: A

SOLUTION

v1 = v2 will work if v1 and v2 are variables of the same type. If they are made of the same type of components but are known as different data types, then it won't.


Q. 189822 After the statement, typedef float money;
The statement that will generate an error is


A. money membership;

B. float charges;

C. typedef salary amount;

D. typedef money fees;

Right Answer is: C

SOLUTION

typedef salary amount;    
Here, salary is not a data type.


Q. 189823 Out of the given options, the statement that would make the statement incorrect is
"An array of structures has elements ...”


A. of different data types.

B. of the same data type.

C. made of different data types.

D. that are structures.

Right Answer is: A

SOLUTION

Arrays are collections of analogous elements.


Q. 189824 The syntax for accessing a structure element is


A. struct name.element-name.

B. element-name.structure name.

C. element-name.struct name.

D. structure-name.element-name.

Right Answer is: D

SOLUTION

The structure variable name followed by a period (.) and the element name references to that individual structure element. The first component of an expression involving the dot operator is the name of the specific structure variable, not the name of the structure specifier.


Q. 189825 A structure within a structure is called


A. enclosed structure.

B. contained structure.

C. nested structure.

D. doubled structure.

Right Answer is: C

SOLUTION

A structure can be nested inside another structure. Following code fragment illustrates it :
struct addr
{
    int hno;
    char area[26];
    char city[26];
    char state[26];
};
struct emp
{
    int empno;
    char name[26];
    char desig[16];
    addr address;
    float basic;
};
emp worker;    


Q. 189826 Consider the structure:
struct stu
{
   int rolno;
   char name[25];
   float marks[5];
};
stu learner;
To reference marks of 3rd subject of structure learner, we shall write


A. stu.learner.

B. learner.marks.

C. learner.marks[2].

D. learner.marks[3].

Right Answer is: C

SOLUTION

When a structure element happens to be an array, it is treated in the same way as arrays are treated. The only additional thing to be kept in mind is that, to access it, its structure name followed by a dot (.) and the array name is to be given.
The given fragment declared a structure variable learner of structure type stu that contains an element which is an array of 5 floats to store marks of a student in 5 different subjects.  


Q. 189827 When the structure is defined without a tag, the number of variables that can be declared is/are


A. one

B. two.

C. three.

D. of any number.

Right Answer is: A

SOLUTION

When the structure tag is omitted, only one structure variable is needed.
For example,
struct
{
short day;
short month;
short year;
} birth_date;
declares one variable birth_date as defined by the structure preceding it, but no more structure variables can be created with it.


Q. 189828 A structure may be local (to a function), if defined


A. outside the function.

B. only in one function.

C. within a function.

D. with a local keyword.

Right Answer is: C

SOLUTION

A structure may be local (to a function), if defined within a function. No function other than the one which defines it, can access it (the structures). A structure may be global (to all functions within a program) if defined outisde all functions. That is, any function can then access it.


Q. 189829 Consider the following fragment code.
struct add
{ int houseno;
char area[26];
char city[26];
char state[26];
};
In the above definition, the structure tag is


A.

houseno.

B. state.

C. add.

D. city.

Right Answer is: C

SOLUTION

Here, the add is a structure tag and it identifies this particular structure and its type specifier.


Q. 189830 To define a structure -


A. give keyword struct, followed by tag, followed by members within braces.

B. give keyword  structure, followed by members within braces.

C. give keyword struct, followed by the tag and members, within braces.

D. give tag, followed by members within braces.

Right Answer is: A

SOLUTION

A structure is a collection of variables referenced under one name. The keyword struct tells the compiler that a structure is being defined.
For example,
struct date
{
  short day;
  short month;
  short year;
};
Here, the date is a structure tag and it identifies this particular data structure and its type specifier.


Q. 189831 Data members of a structure can be


A. only public.

 

B. only private.

 

C. only protected.

 

D. public, private, protected.

 

Right Answer is: D

SOLUTION

All members are public by default but can be made protected and private.


Q. 189832 A structure is declared with the keyword


A. structure.

B. struct.

C. define.

D. tag.

Right Answer is: B

SOLUTION

A structure is a collection of variables referenced under one name. The keyword struct tells the compiler that a structure is being defined.


Q. 189833 The assignment possible for similar structures is


A. ==.

B. !=.

C. =.

D. !!=

Right Answer is: C

SOLUTION

Structure assignemnt is possible only if both the structures are of same structure type.


Q. 189834 By default all members of a class are


A. public.

B. private.

C. protected.

D. default.

Right Answer is: B

SOLUTION

By default all members of a class are private. Private access specifier specify that the member-functions or member-variables cannot get accessed outside the class.


Q. 189835 The invalid structure name is


A. sTUDENT;.

B. EmPlOyEe;.

C. 1student;.

D. _student;.

Right Answer is: C

SOLUTION

The naming system of a structure follows the simple rules like the naming system of a variable. As a variable name cannot start with a number so in the same way the name of the structure cannot start with a number.


Q. 189836 Each instance of a structure is known as


A. member.

B. variable.

C. component.

D. tag.

Right Answer is: B

SOLUTION

Each instance of a structure is known as the structure variable.


Q. 189837 A structure can be passed to a function by


A. call by reference only.

B. call by value only.

C. call by reference as well as call by value.

D. variables.

Right Answer is: C

SOLUTION

A structure variable can be passed by value as well as by reference.Pass-by-Value makes a copy of the variable and can be quite slow and inefficient if the variable is large like an array. C++ also allows Pass-by-Reference where the address of the variable is passed in. It is useful when original values are to be changed.


Q. 189838 - > is called as


A. pointer operator.

B. address of operator.

C. reference operator.

D. member access operator.

Right Answer is: D

SOLUTION

- > is the member access operator to access the pointers being declared, inside a structure.


Q. 189839 A structure is sometimes known as a


A. class.

B. conglomerate data type.

C. public class.

D. default class.

Right Answer is: B

SOLUTION

A structure is known as a conglomerate data type because it is a group of several variables under one roof.


Q. 189840 The statement to access an element or member "var" of structure b is


A. b > var.

B. b- > var.

C. b.var.

D. var.b.

Right Answer is: C

SOLUTION

To access a variable or member of a structure we use ‘.’ operator. The syntax to access a member of structure is – Structure_name.Member_name


Q. 189841 The data type struct is a 


A. logical collection of related disimilar data elements.

B. logical collection of related similar data elements.

C. collection of numbers.

D. collection of arrays.

Right Answer is: A

SOLUTION

Data type struct is a logical collection of related dissimilar data elements that can be used as a single unit for Input/Output operation.


Q. 189842 Given the following lines of code,
struct newemp
{
      int code;       char name[20]; }; newemp NE[25];   In order to access the data of the third employee in the list, use  


A. NE[i].code and NE[i].name

B. NE[4].code and NE[4].name

C. NE[3].code and NE[3].name

D. NE[2].code and NE[2].name

Right Answer is: D

SOLUTION

For all arrays in C++, the indexing begins at 0. Therefore, when we want to access the data of the third employee in the list, then the 2nd index structure name will be written.


Q. 189843 A macro without arguments is treated like a


A. text.

B. variable.

C. symbolic constant.

D. null value.

Right Answer is: C

SOLUTION

A macro with arguments has its arguments substituted for replacement text, when the macro is expanded. A macro substitutes text only; It does not check for data types.


Q. 189844 Given the following structure definition, how will you display complete name of person P1? struct name{ char title[5]; char fname[10]; char lname[10]; }; struct person{ int code; name p; }; person P1;


A. cout<< P1.title<< P1.fname<< P1.lname;

B. cout<< p.title<< p.fname<< p.lname;

C. cout<< P1.p.title<< P1.p.fname<< P1.p.lname;

D. cout<< P1.p.title<< p.fname<< p.lname;

Right Answer is: C

SOLUTION

P1 is an instance of structure person that includes name, which in itself is another structure.
So, complete access can be done by the following statement: P1.p.title, P1.p.fname, P1.p.lname


Q. 189845 Consider the following structure S:
struct S
{
int x; char z;
};


A. S V={12, 'A'}; is a valid statement

B. S V; V={23, 'X'}; is a invalid statement.

C. S.V.x=10; S.V.z= 'Z'; is a valid statement

D. S V.x=10; S V.z= 'Z'; is a invalid statement

 

Right Answer is: A

SOLUTION

When we declare an instance of a structure, then simultaneously it has to be initialized.


Q. 189846 Which of the following is incorrect?


A. the entire structure may be returned by a function.

B. a function may return a reference to a structure.

C. a function may return the members of a structure.

D. a function may accept the members of a structure.

Right Answer is: C

SOLUTION

a function may return the members of a structure , Only one value can be returned by a function, either the whole structure or just one member.


Q. 189847 In the given function prototype - void fun(ABC &, char[]);


A. Structure variable will be passed by reference and the array by value

B. Structure variable and the array will be passed by reference

C. Structure variable will be passed by value and the array by reference

D. Structure variable and the array will be passed by value

Right Answer is: B

SOLUTION

For ABC, a reference variable is being used while for char, it is being passed by value.


Q. 189848 To terminate a structure, use:


A. ;

B. :

C. :

D. }

Right Answer is: A

SOLUTION

While terminating a structure, a semi colon is used to end this up.


Q. 189849 When a structure is passed by reference,


A. any change made is only temporary.

B. changes are made in the original values of the variable.

C. reference to the entire structure can’t be passed.

D. changes cannot be made when reference to a structure is passed.

Right Answer is: B

SOLUTION

When a structure is passed by reference the called function declares a reference for the passed structure and refers to the original structure elements through its reference. Thus, the called function works with the original values.


Q. 189850 To Pass a structure to a function, by value


A. pass a reference to it.

B. pass its address using a pointer variable.

C. pass it as a structure variable.

D. pass it as an array.

Right Answer is: C

SOLUTION

When a structure is used as an argument to a function, the entire structure is passed using the standard call-by-value method. This means that any changes made to the contents of the structure inside the function to which it is passed do not affect the structure used as an argument.


Q. 189851 Preprocessor commands begin with a
 


A. dollar sign.

B. period.

C. underscore.

D. pound sign.

Right Answer is: D

SOLUTION

Preprocessor commands are called DIRECTIVES and begin with a pound/hash symbol (#). No white space should appear before the # and a semi colon is NOT required at the end.


Q. 189852 In a class, all members are


A. public by default.

B. protected by default.

C. private by default.

D. global.

Right Answer is: C

SOLUTION

In a class, all members are private by default, on the other hand, structure is actually a class (in C++) declared with keyword struct. By default, all members are public in a structure.


Q. 189853 Consider the following snippet code. struct speed { float time; int distance }; The output of the following code will be


A.

speed s1 = {27,12.5};

B.

speed s1 = {12.5,56.4};

C.

speed s1 = {11.45,12};

D.

speed s1 = {“km”,273,12.5};

Right Answer is: C

SOLUTION

It is correct because it is assigning values of float type time and int type distance.


Q. 189854 Consider the following lines of code:
struct studentType { char name[27]; double gpa; int sID; char grade; }; int *p; double *q; char *chPtr; studentType *stdPtr;  The statement “stdPtr++” increments the value of stdPtr in the range 


A. 0- 10 bytes.

B. 10-20 bytes.

C. 20-40 bytes.

D. 40-80 bytes.

Right Answer is: C

SOLUTION

It increments the pointer by the size of the structure.


Q. 189855 Out of the following statements, the correct statement is


A. typedef provides an alias name to any variable, whether new, or existing.

B. typedef gives a name to existing data types.

C. typedef does not create an alias variable.

D. typedef  is not the keyword.

Right Answer is: B

SOLUTION

 typedef declaration lets you define your own identifiers that can be used in place of type specifiers such as int, float, and double.


Q. 189856 struct StudentRecord {
            char *name;    // student name             double hw[3];  //home work grades             double test[2]; // test grades             double avg;    // final average                                                }; The number of components in the given structure is


A. 3.

B. 2.

C. 6.

D. 4.

Right Answer is: D

SOLUTION

The above given structure has four components namely *name, hw[], test[] and avg.


Q. 189857 The error in the below code is struct A
{ int x=2; char z='A'; }; A a; a.x=12; a.z='Z';


A. a.x=12;

B. a.z=’Z’

C. int x=2; char z=’A’;

D. };

Right Answer is: C

SOLUTION

Members cannot be initialized inside a structure.


Q. 189858 The  error in the following structure definition, is
struct info{ int flatno; 
char building[20]; char city[15]; int pincode; date date_purchased; } ; struct date{ int day; int mon; int year; } ;


A. int pincode;

B. date should be declared before info.

C. date date_purchased;

D. program is correct.

Right Answer is: B

SOLUTION

Since, date is a nested structure, so it should be declared before info.


Q. 189859 Given the following definitions and declarations :
struct date{ int day; int mon; int year; } ; struct DATE{ int day; int mon; int year; } ; date d1,d2; DATE D1,D2; The incorrect statement is


A. d1=d2;

B. D1=d2;

C. date d3={22,8,2005};

D. DATE D={4,3,1999};

Right Answer is: A

SOLUTION

D1=d2 is wrong,  because both are different data types.
date d4; d4={12,2,2005}; is incorrect because it is assigning values to a declared member.


Q. 189860 Consider the structure below; to access x using either variable, the statement would be
struct A
{
int x;
int y;
char z;
};
A a1,*a2;


A. a1.x or a2.x.

B. a1.x or a2->x.

C. a1->x or a2.x.

D. a1->x or a2->x.

Right Answer is: B

SOLUTION

a1.x or a2->x, a2 is a pointer variable. Hence, uses -> to access the member.


Q. 189861 The error in the following structure definition, is 
struct 
{ int x;
int y; char c; } var1, var2, var3;


A. struct abc{int x;

B. char c[20];

C. };

D. }var1;

Right Answer is: D

SOLUTION

When tag is missing, only one variable can be declared. Here, three have been declared, therefore, this is wrong.


Q. 189862 The error in the following structure definition, is
struct size { 
int breadth; int height; }


A. structure size

B. int length, breadth, height;

C. }s1

D. };

Right Answer is: D

SOLUTION

A semicolon should always terminate a structure.


Q. 189863 Given below, structure S,
struct S
{
int x;
char z;
} ;   ,   the statement


A. S V={12,’A’}; is a valid statement.

B. S V; V={23,’X’}; is  invalid statement.

C. S.V.x=10; S.V.z=’Z’; is a valid statement.

D. S V.x=10; S V.z=’Z’; is invalid statement.

Right Answer is: A

SOLUTION

When we declare an instance of a structure, then simultaneously it has to be initialized.


Q. 189864 Given the following structure definition, the command to display complete name of person P1 is
             struct name{ char title[5]; char fname[10]; char lname[10]; }; struct person{ int code; name p; }; person P1;


A. cout<< P1.title<< P1.fname<< P1.lname;

B. cout<< p.title<< p.fname<< p.lname;

C. cout<< P1.p.title<< P1.p.fname<< P1.p.lname;

D. cout<< P1.p.title<< p.fname<< p.lname;

Right Answer is: C

SOLUTION

P1 is an instance of structure person which includes name which in itself is another structure. So, complete access can be done by the statement :
       P1.p.title, P1.p.fname, P1.p.lname


Q. 189865 The output of the following code snippet is
#include< iostream.h >
struct Pt
{
int x,y;
};
void disp(Pt p)
{
cout << ' '<< p.x <<' ' << p.y;
}
void main()
{
Pt A,B,C={25,50};
A=C;
C.x+=5;
B=C;
B.y+=10;

A.x=22;
disp(A);
disp(B);
disp(C);
}


A. 22 50 30 60 25 50

B. 22 50 30 60 30 50

C. 25 50 25 60 30 50

D. 25 50 30 60 30 50

Right Answer is: B

SOLUTION

The sequence of calling functions is : disp (A); disp (B); disp (C);, and the output is displayed according to this sequence.


Q. 189866 Given the following lines of code,
struct newemp
{
int code;
char name[20]; }; newemp NE[25]; In order to access the data of the third employee in the list, we use


A. NE[i].code and NE[i].name

B. NE[4].code and NE[4].name

C. NE[3].code and NE[3].name

D. NE[2].code and NE[2].name

Right Answer is: D

SOLUTION

Any array starts from index 0. So, the third employee’s details can be obtained by NE[2].name and NE[2].code.


Q. 189867 The error in the code given below is:
struct A
{
int x=2;
char z='A';
};
A a;
a.x=12;
a.z='Z';


A. No error.

B. Values of x and z in A are being overwritten.

C. Member z has a value same as the structure name.

D. x and z cannot be assigned values in definition.

Right Answer is: D

SOLUTION

Variables are never initialized during a structure declaration.


Q. 189868 Given the following structure, the command to access r and x in vb is
struct A
{
int x;
int y;
char z;
};

struct B
{
int r;
A mn;
};
B vb;


A. vb.r and mn.x.

B. B.vb.r and B.vb.x.

C. B.vb.r and
A.mn.x.

D. vb.r and vb.mn.x.

Right Answer is: D

SOLUTION

r is the member of structure B and x is a member of structure A, which has been nested inside B.


Q. 189869 The error in the below code is
struct
{
int x=10;
int y;
char z[10];
}a1,a2;


A. There is a character array as a member.

B. When tag is missing, only one variable can be declared.

C. x value cannot be defined in the structure.

D. Without tag name, variables cannot be declared.

Right Answer is: C

SOLUTION

A value can never be assigned inside a structure.


Q. 189870 When accessing a structure member, the identifier on the left hand side of the dot operator, is the name of


A. a structure member.

B. a structure tag.

C. a structure variable.

D. the keyword struct.

Right Answer is: C

SOLUTION

The dot operator has a structure variable on the left and structure member on the right side.


Q. 189871 To define a structure


A. give keyword struct, followed by tag, followed by members within braces.

B. give keyword structure, followed by members within braces.

C. give keyword struct, followed by the tag and members, within braces.

D. give tag, followed by members within braces.

Right Answer is: A

SOLUTION

The syntax for structure declaration is :     struct structure_name
  {
     member_type1 member_name1;
     member_type2 member_name2;
     member_type3 member_name3;
    .
    .
  } object_names;


Q. 189872 The error in the given code is:
#include< iostream.h >
void main ( )
{
struct Student
{
char stu_name[20];
char stu_sex;
int stu_age = 17;
} student ;
gets(stu_name);
gets(stu_sex);
}


A. gets(stu_name);
gets(stu_sex);
int stu_age = 17
;

B. int stu_age = 17;

C. gets(stu_name);
gets(stu_sex);

D. gets(stu_name);

Right Answer is: A

SOLUTION

gets( stu_name); because methods are accessed with dot operator.
int age=17; because, we cannot initialize variables within a structure.


Q. 189873 The line having an error in the code below is:
# include< iostream.h>
void main()
{
struct employee
{
char name[25];
int age;
int salary;
};
employee emp;
strcpy(emp.name,"rohan");
emp.age=37;
cout << name;
cout << emp.age;
}


A. emp.age=37;

B. cout << name;

C. strcpy(emp.name,"rohan");

D. employee emp;

Right Answer is: B

SOLUTION

It should be cout << emp.name.


Q. 189874 The function setdata()


A. sets the data items to given values.

B. displays the data items.

C. receives the values of data items.

D. prints the data items.

Right Answer is: A

SOLUTION

It assigns data in a specified format to the data transfer object or the clipboard data object.


Q. 189875 The class and the constructor function within it


A. can have different names.

B. must have same names.

C. may or may not have same names.

D. can never have same names.

Right Answer is: B

SOLUTION

The constructor is a special member function that is automatically called when an object is created. It has a same name as that of a class.


Q. 189876 Usually the data and member functions in a class are


A. public and private respectively.

B. public.

C. private.

D. private and public respectively.

Right Answer is: D

SOLUTION

The data within a class is private, i.e., the data is hidden so that it will be safe from accidental manipulation. The functions are public so that they can be accessed from outside the class.


Q. 189877 If, we declare the object of a particular class type and the class does not have a constructor, then


A. it would be compiler error.

B. default constructor gets called automatically.

C. default constructor has to be called explicitly.

D. it would give run time error.

Right Answer is: B

SOLUTION

When no constructor is present in the class the compiler builds an implicit constructor.


Q. 189878 The destructors used in C++ program


A. do not have a return value.

B. have a return value .

C. take arguments.

D. do not gets automatically called.

Right Answer is: A

SOLUTION

The constructors can take any one or more arguments, whereas the destructors take no arguments. Both the constructors and destructors are called automatically.


Q. 189879 If, I want to create a destructor having class name “example”, then the syntax, is


A. *example( ).

B. ~example( ).

C. ^example( ).

D. &example( ).

Right Answer is: B

SOLUTION

A destructor has the same name as the constructor (which is same as the class name) but is preceded by a tilde.


Q. 189880 When an object is destroyed, the function that automatically gets called is


A. destructor.

B. constructor.

C. malloc.

D. calloc.

Right Answer is: A

SOLUTION

The destructors are used to deallocate memory that was allocated for the object by the constructor.


Q. 189881 A class declared within another class is known as


A. enclosing class.

B. nested class.

C. inline class.

D. outer class.

Right Answer is: B

SOLUTION

A class may be declared within another class. A class declared within another class is called a nested class. The outer class is known as enclosing class and the inner class is known as nested class.


Q. 189882 The class specification takes place in two parts :


A. class definition and class method defintions.

B. class declarations and class method defintions.

C. class definition and class declarations.

D. class method defintions and class declarations.

Right Answer is: A

SOLUTION

The class specification takes place in two parts : a) class definition, which describes the component members (both data members and function members) of the class. b) Class method definitions which describe how certain class member functions are implemented.


Q. 189883 When an object is declared outisde a function, it is known as


A. global object.

B. global class.

C. local object.

D. local class.

Right Answer is: A

SOLUTION

An object is said to be a global object if it is declared outside all the function bodies and it means that this object is globally available to all the functions in the program i.e., this object can be used anywhere in the program.


Q. 189884 When an object is declared within a function, it is known as


A. global object.

B. local object.

C. local class.

D. global class.

Right Answer is: B

SOLUTION

An object is said to be a local object if it is declared within a function, which means that this object is locally available to the function that declares it and cannot be used outside the function declaring it.


Q. 189885 The OOP feature that binds data and associated functions together is known as


A. data abstraction.

B. inheritance.

C. encapsulation.

D. polymorphism.

Right Answer is: C

SOLUTION

The wrapping up of data and functions into single unit (class) is known as encapsulation. The programmer cannot directly access data. The data is accessible only through functions present inside class.


Q. 189886 Array result contains 10 objects. To access data member marks of 3 object in array, we'll write


A. result[3].marks.

B. result[2].marks.

C. marks[2].result.

D. marks[3].result.

Right Answer is: B

SOLUTION

C++ supports array of any data type including class type. Array having class type elements is known as array of objects. Here, the array marks contains 10 objects, namely, marks[0], marks[1], marks[2],..marks[9]. To access data member marks of 3rd object in the array, we will write : result[2].marks.


Q. 189887 When an object is passed by value,


A. the function creates its own copy of object and works with its own copy.

B. its memory address is passed to the function.

C. the function creates a third copy and works on it.

D. then changes made to the object inside function affect original object.

Right Answer is: A

SOLUTION

An object can be passed in two ways - by value and by reference. When an object is passed by value, the function creates its own copy of the object and works with its own copy. Therefore, any changes made to the object inside the function do not affect the original object. However, when an object is passed by reference, its memory address is passed to the function so that the called function works directly on the original object used in the function call.


Q. 189888 A member function can access


A. ordinary members.

B. static members.

C. ordinary and static members.

D. global data members.

Right Answer is: C

SOLUTION

A member function can access both static and ordinary data members whereas static member function can access only static members.


Q. 189889 The non member functions have access


A. only to private members of the class.

B. only to public members of the class.

C. to both private members and public members of the class.

D. only to inline inline functions.

Right Answer is: B

SOLUTION

Member functions have full access privilege to both the public and private members of the class while, in general, nonmember functions have access only to public members of the class.


Q. 189890 The different access levels in a class are


A. protected, personal, public

B. private, public, preserved

C. public, private, protected

D. public, protected, personal

Right Answer is: C

SOLUTION

The classes in C++ have 3 important access levels. They are Private, Public and Protected. Private: The members are accessible only by the member functions or friend functions. Protected: These members are accessible by the member functions of the class and the classes which are derived from this class. Public: Accessible by any external member.


Q. 189891 A class binds


A. data and structures.

B. data and functions.

C. objects and structures.

D. functions and structures.

Right Answer is: B

SOLUTION

Encapsulation is the concept of binding of data and functions.The data members are allowed to access by appropriate class functions or methods.Data members can't access from outside class.


Q. 189892 Consider the following fragment :
class B
{
int x;
protected:
int z;
public:
void getDat(int, int);
void showDat();
};
The member functions of class B are


A.  

only x.

 

B.  

both x and z.

 

C.  

getDat().

 

D.  

getDat and showDat().

 

Right Answer is: D

SOLUTION

There are two member function in class B : getDat() and showDat(). Here, the scope of functions is public. Member functions are set of operations that may be applied to objects of that class.


Q. 189893 Out of the following statements, the correct statement is


A. a member function can call another member function

B. member functions cannot call non-member functions

C. A class with one static data must have one static member function

D. Callling a member function of an object is also known as sending message to the object.

Right Answer is: D

SOLUTION

The private data of a class can be accessed only through the member functions of that class. The public members can be accessed by non-member functions through the objects of that class. The public member functions of a class are called by non-member functions using the objects. The general form for calling a member function is : object-name.function-name(actual arguments);


Q. 189894 The operator which is used in situations, where a global variable exists within the same name as the local variable is called


A. arithmetic operator.

B. increment operator.

C. scope resolution operator.

D. dot operator.

Right Answer is: C

SOLUTION

Scope resolution operator is used in C++ class, when the member functions are declared outside the class definition.


Q. 189895 The class is declared with the keyword


A. member.

B. classname.

C. class.

D. public.

Right Answer is: C

SOLUTION

The syntax of class declaration is: 

class
{
   
    access specifier :
     data members; member functions;

};


Q. 189896 The function designed to speed up the program is


A. constructor.

B. destructor.

C. anonymous.

D. inline.

Right Answer is: D

SOLUTION

The inline functions are a C++ enhancement designed to speed up programs. The distinction between normal functions and inline functions is the different compilation process for them.


Q. 189897 Through private and protected members, a class enforces


A. data hiding.

B. inheritance.

C. polymorphism.

D. encapsulation.

Right Answer is: A

SOLUTION

A class groups its members into three sections : private, protected and public. The private and protected members remain hidden from outside world. Thus, through private and protected members, a class enforces data hiding.


Q. 189898 A member function can access


A. only static members.

B. only ordinary members.

C. both ordinary members as well as static members.

D. only one ordinary member.

Right Answer is: C

SOLUTION

A member function can access both ordinary members as well as static members whereas a static member function can access only static members.


Q. 189899 In C++ programs, when an object is first created the special member function, which is automatically called is


A. destructor.

B. constructor.

C. malloc.

D. calloc.

Right Answer is: B

SOLUTION

The constructor is a special member function that allows us to set up values while defining the object, without the need to make a separate call to a member function.


Q. 189900 If, a class object is declared within the function that defines this class type, then it is called a


A. inner class.

B. local class.

C. global class.

D. sub class.

Right Answer is: B

SOLUTION

A class is said to be a local class, if its definition occurs within the class body.


PreviousNext