C++, Python Notes and questions
C++, Python Notes and questions
Which of the following languages is a subset of C++ language? C language Java Language C# language B language C language
Both Statically and dynamically
Which of the following correctly describes C++ language? Statically typed language Dynamically typed language Typeless-language Statically typed language
typed language
Which of the following keyword supports dynamic method
abstract Virtual Dynamic Typeid Virtual
resolution?
Which of the following language is not supported by C++? Exception Handling Reflection Operator Overloading Namespaces Reflection
Which of the following language feature is not an access specifier in
public private protected internal internal
C++?
What does STL stand for? Simple Template Library Standard Template Library Static Type Library Single Typebased-Library Standard Template Library
C++ programs are directly C++ programs are first compiled to C++ programs are directly
Which of the following is the most common way of C++ programs are interpreted by A C++ editor directly compiles and
compiled into native code by a intermediate code by a compiler and then compiled into native code by a
implementingC++? an interpreter executes the program
compiler executed by a virtual machine compiler
What is the implicit pointer that is passed as the first argument for
self’ pointer std::auto_ptr pointer ‘Myself’ pointer ‘this’ pointer ‘this’ pointer
nonstatic member functions?
If X is the name of the class, what is the correct way to declare copy
X(X arg) X(X* arg) X(const X* arg) X(const X& arg) X(const X& arg)
constructor of X?
Which of the following operator cannot be overloaded? =' (assignment operator) == (equality operator) –> (rrow operator) :: (scope resolution operator) :: (scope resolution operator)
. (dot or member access
Which of the following operators can be overloaded? & (address-ofoperator) sizeof operator ?: (conditional operator) & (address-ofoperator)
operator)
By providing at least one pure By providing at least one pure
virtual method (function By declaring at least one method abstract By declaring the class abstract with It is not possible to create abstract virtual method (function
How do we declare an abstract class?
signature followed by ==0;) in using the keyword ‘abstract’ in a class the keyword ‘abstract’ classes in C++ signature followed by ==0;) in a
a class class
By making all the methods By making all the methods abstract using By declaring the class as interface It is not possible to create By making all the methods pure
How do we declare an ‘interface’ class?
pure virtual in a class the keyword ‘abstract’ in a class with the keyword ‘interface’ interface class in C++ virtual in a class
A copy of the static member is
How many copies of a class static member are shared between A copy of the static member is A copy is created only when at least one No memory is allocated for static A copy of the static member is
created for each instntiation of the
objects of the class? shared by all objects of a class object is created from that class members of a class shared by all objects of a class
class
const members can be nonconst members can be invoked const members can be invoked
const members can be invoked only on
Which of the following is true about const member functions? invoked on both const as well on const objects as well as none of the above on both const as well as
const objects and not on nonconst objects
as nonconst objects nonconst objects nonconst objects
Which header file should we include for using std::auto_ptr? <memory> <alloc> <autoptr> <smartptr> <autoptr>
Aspect Oriented Programming
STL is based on which of the following programming paradigms? Structured Programming Object Oriented Programming (OOP) Functional Programming Functional Programming
(AOP)
Namespaces refer to the namespaces provide facilities for namespaces provide facilities
Which of the following correctly describes the meaning of Namespaces refer to space between teh Namespaces refer to space
memory space allocated for organizing the names in a program for organizing the names in a
‘namespace’ feature in C++? names in a program between the names in a program
names used in a program to avoid name clashes program to avoid name clashes
Which of the following is the most general exception handler that
catch(std::exception) catch(std::any_exception) catch(…) catch() catch(…)
catches exception of any type?
Which of the following relationship is known as
‘has-a’ relationship ‘is-a’ relationship association relationship none of the above ‘is-a’ relationship
inheritancerelationship?
Question option 1 option 2 option 3 option 4 answer
Following is the not a correct statement for preprocessor directive #include<iostream.h> #define
#include<iostream.h> #include<iostream.h> #define LEFT 1 #define LEFT 1 #define ABS(a) (a)<0 ? –(a) : (a)
declaration? LEFT 1
System programming
Originally ‘C’ was developed as: General purpose language Data processing language None of above General purpose language
language
In C++ if return statements is written in a non-void function without
undefined 1 0 -1 undefined
any specified value, what will be return value of the function?
In C++ how many return statements are allowed in a non-void
1 as many as you like 0 2 as many as you like
function?
In C++ if program executed successfully, following value will be
returned to the calling process, if nothing specified in return 0 1 -1 2 0
statement?
Individual characters in a string are accessed as following cout << S.at(i); cout << S[i]; both a) and b) none cout << S[i];
Which of the following keyword is not used in exception handling Try allow Catch allow
Which of the following is invalid header file name? <iostring> <string> <iostream > <sstream> <iostring>
The pow functions returns _____: int double string float double
Which of the following are valid array declaration int num(5) float avg[5] double[5] marks counter int[5] float avg[5]
char * const ptr1 = “nice”; //this is example of , constant pointer pointer to a constant None of above Both of above constant pointer
int const *ptr1 = &m; // this is example of, Constant pointer pointer to a constant Both of above None of above pointer to a constant
Address assigned to pointer
In the following statement, const char * const cp = “xyz”; contents it points to cannot be changed Both of above None of above Both of above
cp cannot be changed
In C++, symbolic constants created using const enum Both of above None of above Both of above
A friend class in C++, can access the "__________" members of the
private and protected private and public public and protected Public private and protected
class in which it is declared as a friend
A friend function that is a "friend" of a given class is allowed access
public, private, or protected public or private public protected public, private, or protected
to ______data in that class.
Object can be used as a function argument by.. Pass by value Pass by reference None of above All of above All of above
Member function of one class can be friend function of another class TRUE FALSE TRUE
Member function of one class can be friend function of another class
friend class neighbor class sister class inherited class friend class
is called as
in C++, an object can be returned as argument TRUE FALSE TRUE
Following is the dereferencing operator ?:: &* ->> ->* ->*
Inventor of C++ language is John Dell Bjarne Stroustrup Thomusn Steve Karl Thomus Bjarne Stroustrup
Destructor can have following number of argument 2 1 0 -1 0
While executing a program we first need to translate the source
debugging executing compiling compiling
code into object code, it is called as
Array elements are accessed using :: . -> Index number Index number
Following operator cannot be used for operator overloading #VALUE! == sizeof - sizeof
A function that is called automatically when an object is created is
constant constructor static friend constructor
called as
The null character will take space of 0 byte 2 byte 1 byte 8byte 1 byte
This operator is used to allocate memory new delete static real new
Enables the initialization of an object as it is Enables the initialization of an
A constructor Constructs new data type Obtain memory for a new variable None of the above
created object as it is created
When a copy of an entire object is passed to a function, then it is
Pass-by-reference Pass-by-pointer Pass-by-value None of the above Pass-by-value
referred to as
Consider the statements a = 13 ; c = a<< 3 ; (a and c are integers).
104 114 140 141 104
The result assigned to the integer c is
What does C++ append to the end of a string literal constant? a space a number sign (#) an asterisk (*) a null character a null character
Question option 1 option 2 option 3 option 4 answer
he statement int num[2][3]={ {1,2}, {3,4}, {5, 6} }; assigns a value 2 to num[1][2] assigns a value 4 to num[1][2] gives an error message assigns a value 3 to num[1][2] gives an error message
writes the member functions writes the member functions and
The statement fwrite ( (char*)&objl, sizeof(objl) ); writes the data in objl to fl writes the address of objl to fl writes the data in objl to fl
of objl to fl me data of obj 1 to fl
Which of the following type casts will convert an Integer variable
(double) amount (int to double) amount int to double(amount) int (amount) to double (double) amount
named amount to a Double type?
You have assigned the address of Value to the pointer P, Which
cout << P; cout << *Value; cout << &P; cout << * < P; cout << * < P;
statement will display the value stored in Value?
The keyword used to transfer control from a function back to the
switch goto go back return return
calling function is
Which of the following can not be used as identifiers? Letters Digits Underscores Spaces Spaces
A function that calls itself for its processing is known as Inline Function Nested Function Overloaded Function Recursive Function Recursive Function
Variable b will have value 2 if
Observe following function declaration and choose the best answer: Variable b is of integer type Variable a and b are of int type and the Variable b is international scope Variable b will have value 2 if not
not specified when calling
int divide ( int a, int b = 2 ) and will always have value 2 initial value of both variables is 2 and will have value 2 specified when calling function
function
Variables inside parenthesis of functions declarations have _____
Local Global Module Universal Local
level access.
Strings are character arrays. The last index of it contains the null-
\n \t \0 \1 \0
terminated character
Which of the following identifiers is invalid? papername writername typename printname typename
A function that calls itself for its processing is known as Inline Function Nested Function Overloaded Function Recursive Function Recursive Function
Variable b will have value 2 if
Observe following function declaration and choose the best answer: Variable b is of integer type Variable a and b are of int type and the Variable b is international scope Variable b will have value 2 if not
not specified when calling
int divide ( int a, int b = 2 ) and will always have value 2 initial value of both variables is 2 and will have value 2 specified when calling function
function
Variables inside parenthesis of functions declarations have _____
Local Global Module Universal Local
level access.
Strings are character arrays. The last index of it contains the null-
\n \t \0 \1 \0
terminated character
Which of the following identifiers is invalid? papername writername typename printname typename
The assignment always takes place
The lvalue must always be a The rvalue might be a constant, a variable,
In an assignment statement from right to left and never the All of above All of above
variable an expression or any combination of these
other way
It is not C++ statement but the This does not require a semicolon at the end It is a C++ statement that declares It is a C++ statement that
Regarding #define which of the following statement is false? None of the above
directive for the preprocessor of line a constant in C++ declares a constant in C++
Additional information sent when an exception is thrown may be
the throw keyword. the function that caused the error. the catch block. an object of the exception class the catch block.
placed in
have to be redefined in the have to be redefined in the
Pure virtual functions cannot have public access specification. are mandatory for a virtual class None of the above.
inherited class. inherited class.
there are no member cannot be used in inheritance cannot be used in inheritance
A struct is the same as a class except that all members are public. it does have a this pointer.
functions hierarchy hierarchy
The operator that cannot be overloaded is :: () ::
private data members and protected data members and the data members of the derived the data members of the
A friend function to a class, C cannot access public data members and member functions
member functions. member functions. class of C. derived class of C.
Which statement gets affected when i++ is changed to ++i? i = 20; i++; for (i = 0; i<20; i++) { } a = i++; while (i++ = 20) cout << i; i = 20; i++;
If you wanted to sort many large objects or structures, it would be
place them in an array and place pointers to them in an array andg sort place them in a linked list and sort place references to them in an place them in a linked list and
most efficient to
sort the array. the array the linked list. array and sort the array. sort the linked list.
The process of building new classes from existing one is called Structure Inheritance polymorphism Template Inheritance
the class allowing access to
The keyword friend does not appear in the class desiring access to another class the private section of a class. the public section of a class. the private section of a class.
another class.
the normal cout << the cin.get( ) function with two the cin.get( ) function with three the cin.get( ) function with two
You can read input that consists of multiple lines of text using the cin.get( ) function with one argument
combination arguments. arguments. arguments.
Question option 1 option 2 option 3 option 4 answer
are removed from memory permit data to be hidden from other bring together all aspects of an Can closely model objects in the bring together all aspects of an
A property which is not true for classes is that they
when not in use classes. entity in one place. real world. entity in one place.
Which of the following cannot be legitimately passed to a function A constant A variable. A structure A header file. A structure
Class for which two or more than two Class for which copy constructor is Class whose objects will be Class whose objects will be
In which case is it mandatory to provide a destructor in a class? Almost in every class
objects will be created defined created dynamically created dynamically