The syntax of a structure definition takes the following form :
struct tag
{
type variable-name;
type variable-name;
type variable-name;
...
...
} structure-variables;
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.
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.
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.
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.
To store employee's details structure should be used.
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.
When tag is missing, only one variable can be declared. Here, three have been declared and this is wrong.
The structure definition is not terminated properly as the semicolon ';' is missing after the closing brace.
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.
struct time{ int hour;
int min;
int sec;
Related data elements that may be stored as variables of different data types form the components of a structure.
date D, *DT;
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.
The #define preprocessor allows us to define symbolic names and constants. #define allows you to make text substitutions before compiling the program.
A. i & ii.
B. i & iii.
C. ii & iii.
D. i , ii & iii.
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.
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( )
If declared within main() it becomes local to the function main().
A. emp.age=37;
B. cout << name;
C. strcpy(emp.name,"rohan");
D. employee emp;
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
A. array of structures.
B. nested structure.
C. class of structures.
D. group of structures.
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.
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 ); .
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.
A. with any data type.
B. only with fundamental data types.
C. only with user defined data types.
D. only with float data type.
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.
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.
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.
A. money membership;
B. float charges;
C. typedef salary amount;
D. typedef money fees;
typedef salary amount;
Here, salary is not a data type.
A. of different data types.
B. of the same data type.
C. made of different data types.
D. that are structures.
Arrays are collections of analogous elements.
A. struct name.element-name.
B. element-name.structure name.
C. element-name.struct name.
D. structure-name.element-name.
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.
A. enclosed structure.
B. contained structure.
C. nested structure.
D. doubled structure.
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;
A. stu.learner.
B. learner.marks.
C. learner.marks[2].
D. learner.marks[3].
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.
A. one
B. two.
C. three.
D. of any number.
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.
A. outside the function.
B. only in one function.
C. within a function.
D. with a local keyword.
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.
A.
houseno.
B. state.
C. add.
D. city.
Here, the add is a structure tag and it identifies this particular structure and its type specifier.
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.
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.
A.
only public.
B. only private.
C. only protected.
D. public, private, protected.
All members are public by default but can be made protected and private.
A. structure.
B. struct.
C. define.
D. tag.
A structure is a collection of variables referenced under one name. The keyword struct tells the compiler that a structure is being defined.
A. ==.
B. !=.
C. =.
D. !!=
Structure assignemnt is possible only if both the structures are of same structure type.
A. public.
B. private.
C. protected.
D. default.
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.
A. sTUDENT;.
B. EmPlOyEe;.
C. 1student;.
D. _student;.
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.
A. member.
B. variable.
C. component.
D. tag.
Each instance of a structure is known as the structure variable.
A. call by reference only.
B. call by value only.
C. call by reference as well as call by value.
D. variables.
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.
A. pointer operator.
B. address of operator.
C. reference operator.
D. member access operator.
- > is the member access operator to access the pointers being declared, inside a structure.
A. class.
B. conglomerate data type.
C. public class.
D. default class.
A structure is known as a conglomerate data type because it is a group of several variables under one roof.
A. b > var.
B. b- > var.
C. b.var.
D. var.b.
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
A. logical collection of related disimilar data elements.
B. logical collection of related similar data elements.
C. collection of numbers.
D. collection of arrays.
Data type struct is a logical collection of related dissimilar data elements that can be used as a single unit for Input/Output operation.
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
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.
A. text.
B. variable.
C. symbolic constant.
D. null value.
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.
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;
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
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
When we declare an instance of a structure, then simultaneously it has to be initialized.
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.
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.
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
For ABC, a reference variable is being used while for char, it is being passed by value.
A. ;
B. :
C. :
D. }
While terminating a structure, a semi colon is used to end this up.
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.
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.
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.
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.
A. dollar sign.
B. period.
C. underscore.
D. pound sign.
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.
A. public by default.
B. protected by default.
C. private by default.
D. global.
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.
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};
It is correct because it is assigning values of float type time and int type distance.
A. 0- 10 bytes.
B. 10-20 bytes.
C. 20-40 bytes.
D. 40-80 bytes.
It increments the pointer by the size of the structure.
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.
typedef declaration lets you define your own identifiers that can be used in place of type specifiers such as int, float, and double.
A. 3.
B. 2.
C. 6.
D. 4.
The above given structure has four components namely *name, hw[], test[] and avg.
A. a.x=12;
B. a.z=’Z’
C. int x=2; char z=’A’;
D. };
Members cannot be initialized inside a structure.
A. int pincode;
B. date should be declared before info.
C. date date_purchased;
D. program is correct.
Since, date is a nested structure, so it should be declared before info.
A. d1=d2;
B. D1=d2;
C. date d3={22,8,2005};
D. DATE D={4,3,1999};
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.
A. a1.x or a2.x.
B. a1.x or a2->x.
C. a1->x or a2.x.
D. a1->x or a2->x.
a1.x or a2->x, a2 is a pointer variable. Hence, uses -> to access the member.
A. struct abc{int x;
B. char c[20];
C. };
D. }var1;
When tag is missing, only one variable can be declared. Here, three have been declared, therefore, this is wrong.
A. structure size
B. int length, breadth, height;
C. }s1
D. };
A semicolon should always terminate a structure.
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.
When we declare an instance of a structure, then simultaneously it has to be initialized.
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;
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
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
The sequence of calling functions is : disp (A); disp (B); disp (C);, and the output is displayed according to this sequence.
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
Any array starts from index 0. So, the third employee’s details can be obtained by NE[2].name and NE[2].code.
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.
Variables are never initialized during a structure declaration.
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.
r is the member of structure B and x is a member of structure A, which has been nested inside B.
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.
A value can never be assigned inside a structure.
A. a structure member.
B. a structure tag.
C. a structure variable.
D. the keyword struct.
The dot operator has a structure variable on the left and structure member on the right side.
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.
The syntax for structure declaration is :
{
member_type1 member_name1;
member_type2 member_name2;
member_type3 member_name3;
.
.
} object_names;
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);
gets( stu_name); because methods are accessed with dot operator.
int age=17; because, we cannot initialize variables within a structure.
A. emp.age=37;
B. cout << name;
C. strcpy(emp.name,"rohan");
D. employee emp;
It should be cout << emp.name.
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.
It assigns data in a specified format to the data transfer object or the clipboard data object.
A. can have different names.
B. must have same names.
C. may or may not have same names.
D. can never have same names.
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.
A. public and private respectively.
B. public.
C. private.
D. private and public respectively.
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.
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.
When no constructor is present in the class the compiler builds an implicit constructor.
A. do not have a return value.
B. have a return value .
C. take arguments.
D. do not gets automatically called.
The constructors can take any one or more arguments, whereas the destructors take no arguments. Both the constructors and destructors are called automatically.
A. *example( ).
B. ~example( ).
C. ^example( ).
D. &example( ).
A destructor has the same name as the constructor (which is same as the class name) but is preceded by a tilde.
A. destructor.
B. constructor.
C. malloc.
D. calloc.
The destructors are used to deallocate memory that was allocated for the object by the constructor.
A. enclosing class.
B. nested class.
C. inline class.
D. outer class.
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.
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.
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.
A. global object.
B. global class.
C. local object.
D. local class.
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.
A. global object.
B. local object.
C. local class.
D. global class.
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.
A. data abstraction.
B. inheritance.
C. encapsulation.
D. polymorphism.
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.
A. result[3].marks.
B. result[2].marks.
C. marks[2].result.
D. marks[3].result.
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.
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.
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.
A. ordinary members.
B. static members.
C. ordinary and static members.
D. global data members.
A member function can access both static and ordinary data members whereas static member function can access only static members.
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.
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.
A. protected, personal, public
B. private, public, preserved
C. public, private, protected
D. public, protected, personal
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.
A. data and structures.
B. data and functions.
C. objects and structures.
D. functions and structures.
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.
A.
only x.
B.
both x and z.
C.
getDat().
D.
getDat and showDat().
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.
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.
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);
A. arithmetic operator.
B. increment operator.
C. scope resolution operator.
D. dot operator.
Scope resolution operator is used in C++ class, when the member functions are declared outside the class definition.
A. member.
B. classname.
C. class.
D. public.
The syntax of class declaration is:
class
{
access specifier :
data members; member functions;
};
A. constructor.
B. destructor.
C. anonymous.
D. inline.
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.
A. data hiding.
B. inheritance.
C. polymorphism.
D. encapsulation.
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.
A. only static members.
B. only ordinary members.
C. both ordinary members as well as static members.
D. only one ordinary member.
A member function can access both ordinary members as well as static members whereas a static member function can access only static members.
A. destructor.
B. constructor.
C. malloc.
D. calloc.
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.
A. inner class.
B. local class.
C. global class.
D. sub class.