There are four types of scopes provided by C++:
The types of functions provided by C++ are:
1.
2.
A function definition contains a function declaration and body of the function.
When a function prototype appears before the function definition, it is known as global prototyping.
Prototyping is required as compiler carefully compares each use of function with its prototype to check whether the function is invoked properly.
i) int val(int n1, int n);
ii) float sum(float a);
datatype function name (parameter list)
{
body of the function
}
User defined functions are created by the programmer as per the requirement of the program.
Function Main( ) primarily consist of:
a) The data items required and
b) The function calls.
A function in C++ language is a block of code that performs a specific task. It has a name and it is reusable i.e. it can be executed from as many different parts in a C++ program.
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.
In C++ 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. Here we can pass a structure to a function through call by value as well as call by referenc mechanism.
A. Value
B. Reference
C. Value, Reference
D. Reference, Value
The prototype void fun(ABC &, char[]); indicates that arguments are passed by reference. The first argument represents that object is passed as a reference and the second argument is an array of character which by default works on reference.
A. the members are being passed by reference.
B. the first one is passed by value and the other by reference.
C. the members are being passed by value.
D. we cannot tell how the members are being passed.
We can tell how variables are being sent through the function prototype or definition. The function call is the same for call by value and by reference.
A. #include
B. typedef
C. #define
D. macros
The #define is a preprocessor directive that allows us to define symbolic names and constants.
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.
In C++ a structure can be passed to a function through "call by value" as well as "call by reference" mechanism. So if we pass a structure through call by reference then the original value can also get changed.
A. Value to the function
B. Reference to the function
C. Pointer to the function
D. Address to the function
A structure is passed as a value to avoid changes in the actual object during any changes done in the formal argument in a function body.
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 given code has been executed in such a way -
#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};//values of x and y for A,B and C structure variable
A=C; //values of x and y of C assigned to the x and y of A
C.x+=5; //x of C =30
B=C; //values of x and y of C assigned to B
B.y+=10; // y of B = 60
A.x=22; //x of A = 22
disp(A); // calling disp() function and A has passed into it
disp(B); // calling disp() function and B has passed into it
disp(C); // calling disp() function and C has passed into it
}
The output of the code is 22 50 30 60 30 50
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
To access the third element of the list we can use the statement- NE[2].code and NE[2].name
A. it is an array of structure.
B. it is a nested structure with an array.
C. it is an array of nested structure.
D. the nested structure has an array.
EMP[45].salary.tax statement is an array of nested structure.
A. link file.
B. execution file.
C. preprocessor directive.
D. batch file.
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.
A. referencing structures.
B. complex structures.
C. recursive structures.
D. looping structures.
A structure inside another structure is called as nested structure.
A. structure variable will be passed by reference, the array by value.
B. structure variable and the array will be passed by reference.
C. structure variable will be passed by value, 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. money membership;
B. float charges;
C. typedef salary amount;
D. typedef money fees;
typedef salary amount cannot be used because salary is not a fundamental data type.
A. macro replaces a value in the code while, const will declare a variable.
B. macro replaces after compilation while, const is done during compilation.
C. macro substitution may affect size of the EXE file but, not the stack.
D. cost substitution may affect size of the EXE file but, not the stack.
Macros always replace the value of a variable before compilation, while const acts like a simple constant during the compilation.
A. a structure inside a structure.
B. a structure that calls itself.
C. a pointer referencing to itself.
D. a pointer inside a structure.
A self-referential structure has an element that, refers to the structure itself. This is actually a pointer that points to a structure of the same type.
A. tag.
B. Variable.
C. Member name.
D. ;
Tag is the name of the structure, which is being declared after the keyword struct.
A. one more structure member is formed.
B. it is incremented by the size of the structure.
C. there is no change in the pointer.
D. pointer creates one more reference to the structure.
The pointer gets incremented by the size of the structure.
A. functions.
B. data and functions.
C. data and function prototype.
D. data only.
A structure can contain only the data while both data and functions are included in a class.
A. homogeneous data structure.
B. heterogeneous data structure.
C. homogeneous data type.
D. heterogeneous data type.
A structure is a heterogeneous data structure since, it stores different types of data.
A. b > var
B. b - > var
C. b.var
D. var.b
var is a pointer , so to access it b- > var is used.
A. computational functions.
B. manipulative functions.
C. procedural functions.
D. void functions.
The functions that calculate or compute some value and return the computed value are computational functions.
A. passed as value generally.
B. passed as reference.
C. cannot be passed.
D. passed by value and reference both.
In call by reference, instead of passing a value to the function being called, a reference to the original variable is passed.
A. extern.
B. static.
C. register.
D. auto.
extern is used when we have defined the variable elsewhere, and use that variable in our program.
A. call by reference.
B. call by value.
C. changing parameter.
D. changing argument.
In call by reference, the changes are reflected back to the original values.
A. computational function.
B. mathematical function.
C. manipulative function.
D. procedural function.
Functions that perform an action and have no explicit return value are procedural functions.
A. cannot be passed as arguments.
B. can be passed as arguments.
C. can not be passed in a C++ program.
D. works with the copy of original values rather than original values.
When a function is called by reference, then the formal parameters become references to the actual parameters in the calling function.
A. a open parameter list.
B. a closed parameter list.
C. not a parameter list.
D. none of the above.
In above function as type and number of parameters are not specified so it is considered as open parameter list.
A. not related to each other.
B. closely related to each other.
C. are equivalent to each other.
D. fundamental data types.
Arrays and pointers are derived data types. an array can hold multiple elements of same data type.
A function is invoked by providing its function name, followed by the parameters.
‘Void’ data type is used for empty set of values.
No, constants or expressions cannot be passed by reference.
User defined functions are created by the programmer as per the requirement of the program.
A prototype has no body and no code.In other words, a (prototype) declaration introduces a function name to the program. On the other hand, a definition tells the Program, what is the function doing and how is it doing so.
return-type function name (parameter list)
}
A function is a subprogram that acts on data and often returns a value.
The two main parameters that appears while calling a function are:
1. Actual parameter
2. Formal parameter
The keyword that is used to make an argument constant is ‘Constant’.
Yes, an argument can have default values.
Syntax: void function-name (parameter list);
A. structure
B. struct
C. define
D. tag
Structure is a user define data structure that is a collection of various types of data elements. The struct keyword is used to declare the structure.
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 );
The C++ preprocessor is a program that is executed before the source code is compiled. It always begins with a hash "#" and ends without a semicolon ";"
A. emp.age=37;
B. cout << name;
C. strcpy(emp.name,"rohan");
D. employee emp;
name is the member of the structure "employee". so to access any member of a structure we need to use structure variable with the dot operator. So the correct statement will be - cout << emp.name;
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);
stu_name and stu_sex are the members of the structure "Student". so to access it we need to use structure variable i.e. "st". In a structure we can declare the members only but we cannot initialize 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. 10021001
B. 10021100
C. 10011002
D. 20010012
The program will execute as follows -
#include < iostream.h >
struct Sumval
{
int a,b;
}
void Struct_Fun(Sumval Sv)
{
Sv.b = 2.5;
cout<< Sv.a << Sv.b;
}
void main ( )
{
Sumval Sv;
Sv.a=100;
Sv.b=1.5;
Struct_Fun(Sv); // calling Struct_Fun function
cout<< Sv.a << Sv.b;
}
The output will be - 10021001
A. with any data type.
B. only with fundamental data types.
C. only with user defined data types.
D. only with float data type.
C++ allows us to define explicitly new data type names by using the keyword typedef. The typedef does not actually create a new data class, rather it defines a new name for an existing type. It can be used with any data type.
A. create a new user defined structure
B. create a new data type
C. create an alias for an existing data type
D. create new variables for an existing data type
C++ allows us to define explicitly new data type names by using the keyword typedef. Using typedef does not actually create a new data class, rather it defines a new name for an existing type. The syntax to create an alias for the int data type is - typedef int id; Here id is an alias for int data type.
A. money membership;
B. float charges;
C. typedef salary amount;
D. typedef money fees;
The statement "typedef salary amount;" will generate an error as salary is not a data type. Here we can use only the fundamental or basic data types of C++.
A. of different data types.
B. of the same data type.
C. made of different data types.
D. that are structures.
An array always has elements of the same data type
A. structure variable name
B. structure name
C. subscript value
D. structure member name
The syntax to access the members of the structure is - structure-variable.member-name
A. code becomes short.
B. code compiles successfully.
C. code runs successfully.
D. the code becomes easier to read and understand.
Using typedef keyword we can make the code easier to read and understand.
A. None
B. v
C. vi
D. vii
vi, values cannot be assigned this way to a declared structure variable.
A.
that the struct is not a keyword.
B. that the values of x and z in A are being overwritten.
C. that the member z has a value same as the structure name.
D. that the x and z cannot be assigned values in definition.
In C++ we can declare members of a structure only. we cannot initialize it.
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. 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
vb is the variable of B structure and mn is the nested variable of A structure. The statement to access r which is the member of B structure is - vb.r The statement to access x which is the member of A structure is - vb.mn.x
A. int.
B. array.
C. float.
D. typedef.
An alias for structure tag name can be defined using typedef keyword. It defines another name for the structure tag name.
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;
As p1 is the structure variable of person and p is the structure variable of name. The correct statement to display the name is - cout<
A. preprocessor.
B. build-in functions.
C. user-defined functions.
D. module.
The preprocessing phase of a C++ program occurs before a program is compiled. The C++ preprocessor is a program that is executed before the source code is compiled.
A. macro replaces a value in the code while const will declare a variable.
B. macro substitution may affect size of the EXE file but not the stack.
C. const substitution may affect size of the EXE file but not the stack.
D. macro and const replaces values during execution.
macro replaces value before compilation while const will declare a variable during compilation
A. both are of the same data type.
B. both have members of the same data type.
C. tag was omitted while defining the structures.
D. both of them don’t contain arrays.
v1=v2 will work only, when both are of the same data type.
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. with any data type.
B. only with fundamental data types.
C. only with user defined data types.
D. only with float data type.
typedef is used to give an alias name to the existing data types.
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.
Since, the structure variable belong to the structure data type. Therefore, it has to be passed in the form of a structure.
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. 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. 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. 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. structure size
B. int length, breadth, height;
C. }s1
D. };
A semicolon should always terminate a structure.
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. 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 and this is wrong.
A. one.
B. none.
C. many.
D. two.
While declaring a structure without a tag, only one variable can be declared.
A. arrays.
B. nested structure.
C. typedef.
D. # define preprocessor.
typedef defines new name in addition to the existing type name. It does not replace the standard data type name.
A. enclosed structure.
B. nested structure.
C. doubled structure.
D. single structure.
Nested structures contain structures within structures. A structure element may be either complex or simple. The simple elements are any of the fundamental data types of C++ i.e., int, char, float, double. However, a structure may consist of an element that itself is complex i.e., it is made up of fundamental types, e.g., arrays, structures etc.
A. 5 elements.
B. 11 elements.
C. 30 elements.
D. 60 elements.
The total number of elements of a two-dimensional array is get calculated by using the formula - Total_no_of_elements = no_of_rows x no_of_columns. So here the total number of elements is 30.
A. 0 to 35 subscripts.
B. 0 to 34 subscripts.
C. 1 to 35 subscripts.
D. 1 to 34 subscripts.
An array marks of type int with 35 elements will have marks[0] at the first allocated memory location with last subscripts as 34.
A. 'z' character.
B. null character.
C. 'x' character.
D. char character.
A string is defined as a character array that is terminated by a null character. Therefore, the char array are declared one character longer to hold null at the end.
A. null-dimensional array.
B. three-dimensional array.
C. single-dimensional array.
D. two-dimensional array.
Two-dimensional array is the simplest form of multi-dimensional array. It has two dimensions, one represents the row and another represents the column.
A. base type of the array.
B. size of the array.
C. elements of the array.
D. name of the array.
The syntax of an array declaration is - type array-name[size], Here "type" declares the base type of the array, which is the type of each elements of the array.
A.
B.
C.
D.
An array is a collection of variables of the same type that are referenced by a common name. It is of two type i.e. single-dimensional array and multi-dimensional array.
A. element number written within [ ] .
B. type of an array.
C. header file for an array.
D. object of iostream.