0% found this document useful (0 votes)
9 views36 pages

cs201 Mid Term

Cs201 mid term file

Uploaded by

maroshawan2233
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views36 pages

cs201 Mid Term

Cs201 mid term file

Uploaded by

maroshawan2233
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

CS201

MID-Term

Best Collection

ZAIB KHANZADA- MSCS

0331-7273691

Virtual University Of Pakistan


The prototype of friend functions is written:

► Top of the class definition.

► As Private member functions.

► Anywhere inside the class definition

► None of the given options

The second parameter of operator function for >> operator must always be passed

► By reference

► Function takes no argument

► By value

► None of the given options

The first parameter of operator function for << operator,


► Must be passed by value
► Must be passed by reference (Page 446)
► Can be passed by value or reference
► Must be object of class

The dynamic memory allocation uses memory from the ____________.

► Stack

► Heap

► System Cache

► None of the given options

Which statement about operator overloading is False?

► New operators can never be created

► Certain overloaded operators can change the number of arguments they take. P# 372

► The precedence of an operator cannot be changed by overloading.

► Overloading cannot change how an operator works on built-in types.

What is the output of the following statement?

int i = 2.5; do { cout i * 2; } while (i > 3 && i < 10);


► 510

►5

► 48

► error

Error due to missing << after cout

We want to access array in random order which approach is better?

► Pointers

► Array index

► Both pointers and array index are better

► None of the given options.

Which of the following syntax will be used to initialize an array of size 5 of int data type to value 0?

► arr[5] = {0} ;

► int arr[5]= 0 ;

► int arr[5] = {0} ;

► int arr[] = 0 ;

The default scope for members of structures is public whereas the default visibility for class members is private.

► True (P 490)

►False

Which of the following is the only operator that the compiler overloads for user define data type?

► Plus (+)

► Minus (-)

► Equal (= =)

► Assignment (=)

If a friend function outside the class declare itself friend of the class, this will neglect concept of ___________.

► encapsulation and data accessing

► encapsulation and data hiding

► friend member functions of the class

► Interface of the class


A special name which is substituted in code by its definition and as a result we get an expanded code is called,

► include

► Directive

► Macro

► Define

Structures help to define program-specific ___________ .

► functions

► datatypes (p 228)

► Arithmetic operations

► None of the given options.

Which of the following is NOT a preprocessor directive?


► #error
► #define
► #line
► #ndefine (Page 272)

*.doc is _____________ by type.


►Sequential File
►Random Access File
►Data File
►Record File

The return type of operator function must always be void.


► True
► False (Page 79)

What does (*this) represents?


► The current function of the class
► The current pointer of the class
► The current object of the class (Page 390)
► A value of the data member

The statement cin.get (); is used to,


► Read a string from keyboard
► Read a character from keyboard (Page 426)
► Read a string from file
► Read a character from file

When we do dynamic memory allocation in the constructor of a class, then it is necessary to provide a
destructor.
►True
►False
Overloaded new operator function takes parameter of type size_t and returns
► void (nothing)
► void pointer (Page 415)
► object pointer
► int pointer

The second parameter of operator functions for << and >> are objects of the class for which we are
overloading these operators.
► True (page 453)
► False

C++ is a case-sensitive language


► True (Page 68) ► False

To include code from the library in the program, such as iostream, a directive would be called up using this
command.
► #include “iostream.h”
► include <iostream.h>
► include <iostream.h>
► #include <iostream.h> (sure)
A template function must have only generic data types.
► True
► False (Page 501)

Template class can not have static variables.


►True
►False (Page 513)

What will be the correct syntax to assign an array named arr of 5 elements to a pointer ptr? (CHECK)
►*ptr = arr ;
►ptr = arr ;
►ptr = arr[5] ;
►*ptr = arr[5] ;

What will be the correct syntax to access the value of fourth element of an array using pointer ptr?
► ptr[3]
► (ptr+3)
► *(ptr+3)
► Both 1and 3

If most significant bit of un-signed number is 1 then it represents a positive number.


► True
► False (Page 251)

If there is a symbol (& sign) used with the variable name followed by data type then it refers to _____ and if
& is being used with variable name then it refers to _____.
► Address of variable, reference variable
► Reference variable, value of variable
► Reference variable, address of variable (Page 367)
► Address of variable, value of variable

We can also do conditional compilation with preprocessor directives.


► True (Page 272)
► False

The default value of a parameter can be provided inside the ________________ CHECK
► function prototype
► function definition (page 249)
► both function prototype or function definition (Page 294)
► none of the given options.

Classes defined inside other classes are called ________ classes


► looped
► nested (Page 492)
► overloaded
► none of the given options.

What purpose do classes serve?


► Data encapsulation
► Providing a convenient way of modeling real-world objects
► Simplifying code reuse
► All of the given options

Every class contains _______________.


► Constructor
► Destructor
► Both a constructor and a destructor (Lecture 27)
► None of the given options

new operator is used to allocate memory from the free store during
►Compile Time
►Run Time
►Link Time
►None of the given options

When an object of a class is defined inside another class then


►Destructor of enclosing class will be called first
►Destructor of inner object will be called first
►Constructor and Destructor will be called simultaneously
►None of the given option

When an object of a class is defined inside another class then, (check)


► Constructor of enclosing class will be called first (Page 464)
► Constructor of inner object will be called first
► Constructor and Destructor will be called simultaneously
► None of the given options

It is possible to define a class within another class.


► True (Page 492)
► False

New and Delete are also used with ___________ and data types as well.
► Class, Objects (Page 342)
► Structures, Pointers
► Both Class and structures
► None of above

With New keyword, data types and class members are initialized with meaningful values instead of garbage.
► True (Page 334)
► False

If we write a statement like s2 = s1; ___ will be the calling object and ____ will be passed to the = operator as
an argument.
► s1, s1
► s1, s2
► s2, s1
► s2, s2

If we write a statement like s2 = s1; s2 will be the calling object and s1 will be passed to the = operator as an
argument. P# 397
cout << setfill(‘0’) << setw(7) << 128 ;
► 0000128
► 0128128
► 1280000
► 0012800

Constructors can not be overloaded like ordinary functions.


► True
► False

Reserve words cannot be used as a variable name.


► True
► False

A template function must have at least ---------- generic data type


► Zero
► One (Page 499)
► Two
► Three

Template functions can also be overloaded (page 503)


► True
► False

We can not make a member function of a class as template function.


► True
► False (Page 506)

When break statement is encountered in switch statement, it


► Stops the entire program
► Stops the execution of current statement
► Exits from switch statement
► None of the given options

We can also define a variable of user define data type (object) as static.
► True
► False

The declarator of Plus (+) member operator function is


► Class-Name operator + (Class-Name rhs) (Page 371)
► operator Class-Name + ( )
► operator Class-Name + ( rhs)
► Class-Name operator + ( )

Let suppose int a, b, c, d, e;, a = b = c = d = e = 42;


This can be interpreted by the complier as:// assignment is right-associative.
► a = (b = (c = (d = (e = 42))));
► (a = b = (c = (d = (e = 42))));
► a = b = (c = (d = (e = 42)));
► (a = b) = (c = d) = (e = 42);

What will be the range of numbers generated by function rand () % 9?


► 0 to 9
► 1 to 9
► 0 to 8
► 1 to 8

When 6 divides any number, the remainder will always be less than 6. Ther result will be between therefore
we will add 1. 1 + rand ( ) % 6; Which of the following is the correct function call having array named student
of 10 elements as a parameter.
► addRecord(student[]) ;
► addRecord(student) ;
► addRecord(student[10]) ;
► addRecord(*student) ;

Declaring structures does not mean that memory is allocated.


Example:
► True
► False

Identifier is a name that can be given to variables, labels and functions.


► True
► False

If a class A declares itself a friend of class B and a class B declares itself a friend of class C then
► Class A is also a friend of class C.
► Class B is also a friend of class A.
► Class A is also a friend of class C if A declares C as its friend.
► Class A is also a friend of class C if C declares A as its friend.

Which of the following statement is best regarding declaration of friend function?


► Friend function must be declared after public keyword.
► Friend function must be declared after private keyword.
► Friend function must be declared at the top within class definition.
► It can be declared anywhere in class as these are not affected by the public and private keywords.

A pointer is a special type of variable that contain ___________


► Memory Address
► Data values
► Both Values and Memory
► None of given of options

When memory for a program is allocated at run time then it is called ________
► static memory allocation
► dynamic memory allocation
► stack memory allocation
► virtual memory allocation

Which of the following function cannot be overloaded?


► Member functions ► Utility functions
► Constructor ► Destructor

The following prototype of unary operator function indicates that it is ____________ .


Date operator++(int )
► Member functions of post increment operator
► Member functions of pre increment operator
► Non-member functions of post increment operator
► Non-member functions of pre increment operator

Static variable which is defined in a function is initialized __________.


► Only once during its life time
► Every time the function call
► Compile time of the program
► None of the above

In the member initialize list, the data members are initialized,


► From left to right
► From right to left
► In the order in which they are defined within class (lecture41)
► None of the given options

If we do not indent the code properly it will __________________


► Be a syntax error
► Be a logical error
► Not be an error at all
► None of the given options

Truth tables are used for analyzing ___________


►logical expressions.
►arithmetic expressions.
►both logical and arithmetic expressions.

Static memory allocation is also known as ____________


► Dynamic allocation
► Compile time allocation
► Run time allocation
► None of the given options

If it is required to copy an array to another array then,


► Both arrays must be of the same size and data type (Page 105)
► Both arrays may be of different size
► Both arrays may be of different data type
► Both arrays may be of different size and type

Dealing with structures and functions passing by reference is the most economical method
► True
► False

eof( ), bad( ), good( ), clear( ) all are manipulators.


► True (Page 433)
► False

When new operator is overloaded at global level then corresponding built-in new operator will not be visible
to whole of the program.
► True (Page 413)
► False

If there is more than one statement in the block of a for loop, which of the following must be placed at the
beginning and the ending of the loop block?
► parentheses ( )
► braces { } (Page 37)
► brackets [ ]
► arrows < >

The return type of a function that do not return any value must be ________
► float
► int
► void (Page 79)
► double

UNIX has been developed in ________ language.


► JAVA
►B
► C (Page 12)
► FORTRAN

Like member functions, ______ can also access the private data members of a class.
► Non-member functions
► Friend functions (Page 346)
► Any function outside class
► None of the given options

The operator function overloaded for an Assignment operator (=) must be


► Non-member function of class
► Member function of class (Page 372)
► Friend function of class
► None of the given options

The endl and flush are _______


► Functions
► Operators
► Manipulators (Page 434)
► Objects
If a symbolic constant has been defined, it will be an error to define it again.
► True (Page 273)
► False

The operator used for casting, in C, is standard ________ operator.


► none of the given options.
► cast (Page 281)
► cost
► const

Which of the following function call is correct for the function prototype?
defaultParameters ( int a, int b = 7, char z = ‘*’ );
► defaultParameters (5);
► defaultParameters (5, ‘8’);
► defaultParameters (6, ‘#’);
► defaultParameters (0, 0, ‘*’, 0);

When an operator function is defined as member function for a binary Plus (+) operator then the number of
argument it take is/are.
► Zero
► One
► Two (Page 371)
► N arguments

We can not define a variable of user-defined data type in the class.


► True
► False (Page 320)

The appropriate data type to store the number of rows and colums of the matrix is____________.
► float
► int
► char
► none of the given options.

Class is a user defined___________.


► data type (page 317)
► memory referee
► value
► none of the given options.

A pointer variable can be,


► Decremented
► Incremented
► Multiplied
► Both Iecremented and Decremented (Page 366)

NULL value has been defined in ______ and _________ header files.
► strings.h and iostream.h
► ctype.h and conio.c
► conio.c and conio.h
► stdlib.h and stddef.h (Page 281)
A Matrix can be composed of ints, floats or doubles as their elements. Best way is to handle this
_______________
► Write a separate class to handle each
► Use templates (Page 527)
► Use strings to store all types
► None of the given options

"setprecision" manipulator will set


► The number of digits after the decimal point (Page 440)
► The number of digits before the decimal point
► The number of digits in a number
► None of the given options

Which of the following option will be true, if we overload "-=" operator?


► only - operator needs to be overloaded
► Minus (-) and = operators need to be overloaded
► the -= operator need to be overloaded explicitly
► the - and = operators need to be overloaded implicitly

When x = 7; then the expression x%= 2; will calculate the value of x as,
►1 ►3 ►7 ►2

setprecision is a parameter less manipulator.


► True
► False (Page 439)

We can change a Unary operator to Binary operator through operator overloading.


►False
►True

delete operator is used to return memory to free store which is allocated by the new operator
►True
►False

What is the functionality of the following statement?


String str[5] = {String(“Programming”), String(“CS201”)};
►Default constructor will call for all objects of array
►Parameterized constructor will call for all objects of array
►Parameterized constructor will call for first 2 objects and default constructor for remaining objects
►Default constructor will call for first 3 objects and Parameterized constructor for remaining objects

What is the sequence of event(s) when allocating memory using new operator?
► Only block of memory is allocated for objects
► Only constructor is called for objects
► Memory is allocated first before calling constructor (Page 414)
► Constructor is called first before allocating memory

Deleting an array of objects without specifying [] brackets may lead to memory leak (check)
►True (MOST)
►False
Which of the following data type will be assumed if no data type is specified with constant?
short
float
int
double

There is an array of characters having name „course‟ that has to be initialized by string „programming‟ of the
following is the correct way to do this
(i) course[] = {„p‟, ‟r‟, ‟o‟, ‟g‟, ‟r‟, ‟a‟, ‟m‟, ‟m‟, ‟i‟, ‟n‟, ‟g‟};
(ii)course[] = „programming‟ ;
(iii)course[12] = “programming” ;
(iv)course = “programming” ;
Choose the correct options.
► (i) and (ii) only
► (i) and (iv) only
► (i) and (iii) only
► (ii) and (iii) only

What will be the correct syntax of the following statement?


ptr is a constant pointer to integer.
const int *ptr ;
const *int ptr ;
int const *ptr ;
int *const ptr ;

Overloaded member operator function is always called by _______


Class
Object
Compiler
Primitive data type

Loader loads the executable code from hard disk to main memory.
True
False

Which of the following is the correct C++ syntax to allocate space dynamically for an array of 10 int?
► new int(10) ;
► new int[10] ;
► int new(10) ;
► int new[10];

The prototype of friend functions must be written ____ the class and its definition must be written ____
► inside, inside the class
► inside, outside the class (Page 346)
► outside, inside the class
► outside, outside the class

To perform manipulation with input/output, we have to include _____ header file.


► iostream.h
► stdlib.h
► iomanip.h
► fstream.h
If we want to use stream insertion and extraction operators with _______ then we have to overload these
operators.
► int, float, double
► objects of class
► int, float, object
► int, char, float

The static data members of a class can be accessed by ________


► only class
► only objects
► both class and objects
► none of given options

Which value is returned by the destructor of a class?


► A pointer to the class.
► An object of the class.
► A status code determining whether the class was destructed correctly
► Destructors do not return a value. (page 323)

When the compiler overloads the assignment (=) operator by default then __________
► compiler does member wise assignment.
► compiler does not allow default overload of assignment (=) operator
► member of the class are not assigned properly
► None of the given options

If text is a pointer of class String then what is meant by the following statement?
text = new String [5];
► Creates an array of 5 string objects statically
► creates an array of 5 string objects dynamically
► Creates an array of pointers to string
► Creates a string Object

Copy constructor becomes necessary while dealing with _______allocation in the class.
► Dynamic memory
► Static memory
► Both Dynamic and Static memory
► None of the given options

Which one of the following is the declaration of overloaded pre-increment operator implemented as member
function?
► Class-name operator +() ;
► Class-name operator +(int) ;
► Class-name operator ++() ; (Page 389)
► Class-name operator ++(int) ;

How many bytes will the pointer intPtr of type int move in the following statement? intPtr += 3 ;
► 3 bytes
► 6 bytes
► 12 bytes
► 24 bytes
A Pointer is a special variable that contain
► Data values
► Memory Address (Page 267)
► Both data and values
► None of the given option

Reference Value Type Data The code is written to __________ the program.
► implement (Page 520)
► design
► analysis
► none of the given options.

Operator overloading can be performed through__________________.


► Classes
► Function (Page 371)
► Operators
► Reference

When a value is referred by a normal variable then it is known as,


► Direct Reference (page 143)
►Indirect Reference.
► Partial Reference
► Proper Reference

Which of the following function is used to increase the size of already allocated memory chunk?
► malloc
► calloc
► realloc (Page 285)
► free

The stream objects cin and cout are included in which header file?
► iostream.h (Page 15)
► fstream.h
► istream.h
► ostream.h

Overloaded delete operator function takes the same parameter as an argument returned by new operator
function.
► True (Page 414)
► False

When an array of object is created dynamically then there is no way to provide parameterized constructors for
array of objects.
► True (Page 414)
► False

C is widely known as development language of _______ operating system.


► Linux
► Windows
► Unix (Page 12)
► Mac OS
Computer can understand only machine language code.
► True
► False

We can not define a function as a friend of a Template class.


► True
► False (Page 151)

What will be the value of ‘a’ and ‘b’ after executing the following statements?
A = 3;
b = a++;
► 3, 4
► 4, 4
► 3, 3
► 4, 3

_______ is used to trace the logic of the program and correct the logical errors.
► Compiler
► Editor
► Linker
► Debugger (Page 13)

new and delete are _____ whereas malloc and free are _____.
► Functions, operators
► Classes, operators
► Operators, functions (Page 342-285)
► Operators, classes

Which situation would require the use of a non-member overloaded operator?


► The overloaded operator is an Assignment operator.
► The left most operand is an object of a class.(Page 375)
► The left operand is built-in data type.
► The operator returns a reference.

The stream insertion and stream extraction operators are already overloaded for ______.
► User-defined data types
► Built-in data types
► User-defined and built-in data types
► None of the given options

The stream insertion and extraction operators are not already overloaded for _______
► Built-in data types
► User-defined data types
► Both built-in and user-defined types
► None of the given options

If we define an identifier with the statement #define PI 3.1415926 then during the execution of the program
the value of PI __________.
► can not be replaced
► None of the given options
► Remain constant. (Page 271)
► can be changed by some operation
Assignment operator is -------------------------associative.
► right
► left
► binary
► unary

When ever dynamic memory allocation is made in C/C++, it is freed_____________.


► Explicitly (Page 527)
► Implicitly
► Both explicitly and implicitly
► None of the given options

Which of the following function do NOT initialize the chunk of memory to all zero?
► calloc() function
► Both malloc() and calloc()
► None of the above
► malloc() function (Page 283)

The function free() returns back the allocated memory got thorough calloc and malloc to _____ .
► stack
► heap
► stack and heap
► None of the given options

width() is member function of _____________


► cin object
► cout object
► Both cin and cout object (Page 440)
► None of the given option

Templates are not type safe.


► true
► false (Page 518)

In if structure the block of statements is executed only,


► When the condition is false
► When it contain arithmetic operators
► When it contain logical operators
► When the condition is true (Page 38)

Header file: fstream.h includes the definition of the stream classes __________.
► ifstream, fstream, cout
► ifstream, fstream, ofstream (Page 199)
► fstream, cin, cout
► None of the above

To access the data members of structure _______ is used.


► dot operator (.) (Page 231)
► * operator
► U operator
► None of given.

Which kind of functions can access private member variables of a class?


► Friend functions of the class (Page 374)
► Private member functions of the class
► Public member functions of the class
► Friend, private and public functions

Friend function of a class is ______________ .


► Member function
► Non-member function (Page 348)
► Private function
► Public function

Function implementation of friend function must be defined outside the class. (Check)
► True
► False (Page 346)

The normal source of cin object is,


► File
► Disk
► Keyboard (Page 424)
► RAM

Which of the following is correct way to initialize a variable x of int type with value 10?
► int x ; x = 10;
► int x = 10;
► int x, x = 10;
► x = 10;

With template function, the compiler automatically detects the passed data and generates a new copy of
function using passed data.
► True Page 510
► False

What will be the correct syntax to declare two-dimensional array of float data type?
► float arr{2}{2} ;
► float arr[2][2] ;
► float arr[2,2] ;
► float[2][2] arr ;

Heap is constantly changing in size.


► True (Page 280)
► False

While calling function, the arguments are assigned to the parameters from _____________.
► left to right. (Page 295)
► right to left
► no specific order is followed
► none of the given options.

A template function must have


► One or more than one arguments
► Only one argument
► Zero arguments
► None of the given options

Structured Query Language is used for ______________


► Databases Management (page 563)
► Networks
► Writing Operating System
► none of the given options

When a call to a user-defined function finishes, the variable defined inside the function is still in existence.
► True
► False (Page 460)

The precedence of an operator can be changed through operator overloading.


► True
► False (Page 372)

"delete" operator is used to return memory to free store, which is allocated by the "new" operator.
► True (page 332)
► False

All preprocessor directives are started with the symbol______.


►*
►+
►@
► # (Page 269)

Within the statement obj1=obj2; obj1 will call the assignment operator function and obj2 will be passed as an
argument to function.
► True
► False

What is the sequence of event(s) when deallocating memory using delete operator?
► Only block of memory is deallocated for objects
► Only destructor is called for objects
► Memory is deallocated first before calling destructor
► Destructor is called first before deallocating memory (Page 414)

The number 544.53 must be stored in _____ data type.


► int
► short
► float (Sure)
► char

A template function can have different type of arguments.


► True (Page 503)
► False

Template class cannot have static variables.


► True
► False

Which of the following is used with bit manipulation?


► Signed integer
► Un-signed integer (Page 245)
► Signed double
► Un-signed double

Structure is a collection of ______________ under a single name.


► Only Functions
► Only Variables (Page 229)
► Both Functions and Variables
► None of the given options

Unary operator implemented as member function takes ____ arguments whereas non-member function takes
_____ arguments.
► One, zero
► Zero, one
► One, two
► Two, one

The first parameter of overloaded stream insertion operator is _________ where second parameter is
_______
► input stream, object of class
► object of class, output stream
► output stream, object of class
► object of class, input stream

The return type of the operator function for << operator is __________.
► class for which we overload operator
► reference of ostream class (ostream&)
► reference of istream class (istream&)
► void

Memory allocated at run time is a system resource and it is the responsibility of _____ to de-allocate the
memory.
► System
► Programmer (Page 331)
► User of program
► None of given options

In C/C++ if we define an array of size eight (8) i.e. int Arr [8]; then the last element of this array will be
stored at,
► Arr[0]
► Arr[8]
► Arr[7]
► Arr[-1]

When an array is passed to a function then default way of passing this array is,
► By data
► By reference (Page 154)
► By value
► By data type

Array is a data structure which store (check)


► Memory addresses
► Variables
► Data Type (Page 100)
► Data

We can also create an array of user define data type.


► True (Page 408)
► False

When we define an array of objects then,


► Destructor will call once for whole array
► Destructor will call for each object of the array
► Destructor will never call
► Depends on the size of array

We can delete an array of objects without specifying [] brackets if a class is not doing dynamic memory
allocation internally.
Ø True
Ø False

Default mechanism of function calling in case of array is _____ and in case of variable is ___.
► Call by value, call by reference
► Call by referene, call by reference
► Call by reference, call by value (Page 119)
► Call by value, call by value

What does STL stand for?


► Source template library
► Standard template library (Page 519)
► Stream template library
► Standard temporary library

Skill(s) that is/are needed by programmer’s _______________________.


► Paying attention to detail
► Think about the reusability
► Think about user interface
► All of the given options (Page 4 & 5)

For which array, the size of the array should be one more than the number of elements in an array?
► int
► double
► float
► char (Page 113)

Friend functions are _____ of a class.


► Member functions
► Public member functions
► Private member functions
► Non-member functions (Page 346)

If overloaded plus operator is implemented as non-member function then which of the following statement
will be true for the statement given below? (Check)
obj3 = obj1 + obj2 ;
► obj2 will be passed as an argument to + operator whereas obj2 will drive the + operator
► obj1 will drive the + operator whereas obj2 will be passed as an argument to + operator
► Both objects (obj1, obj2) will be passed as arguments to the + operator (not sure)
► Any of the objects (obj1, obj2) can drive the + operator

For cin, the source is normally a ________ and destination can be ______.
► File, native data type
► Disk, user-define type
► Keyboard, variable (Page 424)
► File, user-define type

The programs, in which we allocate static memory, run essentially on ________


► Heap
► System Cache
► None of the given options
► Stack (Page 280)

With user-defined data type variables (Objects), self assignment can produce __________. (Check)
► Syntax error
► Logical error
► Link error
► Non of the given options (not sure)

Assignment operator is used to initialize a newly declared object from existing object.
► True (Page 479)
► False
new operator allocates memory from free store and return _____________.
► A pointer
► A reference
► An integer
► A float

"new" and "delete" keywords are _____________ in C++ language.


► Built-in- Function
► Operators
► Memory Allocation Function
► None of the given options

&& is -------------------- operator.


► An arithmetic
► Logical (Page 40)
► Relational
► Unary

Which of the following function(s) is/are included in ctype.h header file?


► isdigit(int c)
► isxdigit(int c )
► tolower(int c)
► All of the above (Page 188)

Disks are _______________ devices having access time of _________ milliseconds.


► Electro-physical, 6
► Electro-Mechanical, 4
► Electro-physical, 5
► Electro-Mechanical, 7 (Page 427)
When we use manipulators in our program then which header file should be included?
► iostream.h
► stdlib.h
► stdio.h
► iomanip.h (Page 433)

We can do arithmetic with references like pointers.


► True
► False (Page 369 )

A function can declare itself a friend of a class.


► True
► False (Page 346)

Which character is inserted at the end of string to indicate the end of string?
► new line
► tab
► null (Page 113)
► carriage return

is used for ___________.


► calculation
► reading
► assigning value to variables (Page 372)
► None of the given options.

The object _______________may be used both for file input and file output
► fstream, (Page 199)
► ifstream,
► ofstream,
► none of the given options.

Which of the following function calling mechanism is true for the function prototype given below?
float func(float &);
► Call by value
► Call by reference using pointer
► Call by reference using reference variable
► None of the given options

Overloaded delete operator function takes parameter of void pointer and returns ________.
► void
► void pointer
► pointer to an object
► pointer of type int

What should be the return type of the constructor?


► void pointer
► int
► same as object type
► constructors do not return any thing (Page 313)

It is a way of reusing the code when we contain objects of our already written classes into a new class,
► True
► False

The functions used for dynamic memory allocation return pointer of type ______
► int
► float
► void
► double

seekg() and write() are functionally _________________ . (CHECK)


► Different
► Identical
► Two names of same function
► None of the above

When a pointer is incremented, it actually jumps the number of memory addresses


► According to data type (Page 160)
► 1 byte exactly
► 1 bit exactly
► A pointer variable can not be incremented

setw is a parameterized manipulator.


► True (Page 437)
► False

In functions that return reference, use __________variables.


► Local
► Global
► Global or static (Page 369)
► None of the given option

The compiler does not provide a copy constructor if we do not provide it.
► True
► False (Page 476)

What is the functionality of the following syntax to delete an array of 5 objects named arr allocated using new
operator?
delete arr ;
► Deletes all the objects of array
► Deletes one object of array (Page 411)
► Do not delete any object
► Results into syntax error

new and delete operators cannot be overloaded as member functions.


► True
► False (Page 414)

The operator function of << and >> operators are always the member function of a class.
► True
► False (Page 446)
If we do not mention any return_value_type with a function, it will return an _____ value.
► int (Page 79)
► void
► double
► float

Suppose a program contains an array declared as int arr[100]; what will be the size of array?
►0
► 99
► 100 (Page 103)
► 101

The name of an array represents address of first location of array element.


► True
► False

Reusing the variables in program helps to save the memory


► True
► False

Which of the following option is true about new operator to dynamically allocate memory to an object?
► The new operator determines the size of an object
► Allocates memory to object and returns pointer of valid type
► Creates an object and calls the constructor to initialize the object
► All of the given options

For non-member operator function, object on left side of the operator may be
► Object of operator class
► Object of different class
► Built-in data type
► All of the given options (Page 375)

The operator function will be implemented as _____, if obj1 drive the - operator whereas obj2 is passed as
arguments to - operator in the statement given below.
obj3 = obj1 - obj2;
► Member function (Page 373)
► Non-member function
► Friend function
► None of the given options

The static data members of a class are initialized _______


► at file scope (Page 466)
► within class definition
► within member function
► within main function

We can also define a user-defines manipulators.


► True
► False

Automatic variable are created on ________.


► Heap
► Free store
► static storage
► stack (Page 461)

If Num is an integer variable then Num++ means,


Ø Add 1 two times with Num
Ø Add 1 with Num
Ø Add 2 with Num
Ø Subtract 2 from Num

If the return type of a function is void then it means that it will,


Ø Return any type of data
Ø Return some specific type of data
Ø Return no data
Ø Return just character data

Which of the following is a valid class declaration?


Ø class A { int x; };
Ø class B { }
Ø public class A { }
Ø object A { int x; };

A stream is an ordered sequence of bytes.


Ø True (Page 423)
Ø False

Which looping process checks the test condition at the end of the loop?
Ø for
Ø while
Ø do while
Ø no looping process checks the test condition at the end

In a group of nested loops, which loop is executed the most number of times?
Ø the outermost loop
Ø the innermost loop
Ø all loops are executed the same number of times
Ø cannot be determined without knowing the size of the loops

Consider the following statements to initialize a two-dimensional array.


Ø int arr[2][3] = {4, 8, 9, 2, 1, 6} ;
Ø int arr[3][2] = {4, 8, 9, 2, 1, 6} ;
Ø int arr[][2] = {{4,8},{9, 2},{1, 6}} ;

Which of the following option(s) are correct to initialize a two-dimensional array with 3 rows and 2
columns?
Ø (ii) only
Ø (iii) only
Ø (ii) and (iii)
Ø and (iii)

There is a pointer variable named ptr of type int then address of which type of variable the ptr will store in it?
Ø variable of type char
Ø variable of type short
Ø variable of type int
Ø variable of type double

The member functions of a class occupy _____ region in memory for ____ object(s) of class.
Ø separate, each
Ø common, all (Page 334)
Ø different, each
Ø different, all

Which of the following is true while overloading operators?


Ø Precedence of an operator can be changed
Ø The arity (number of operands) can be changed
Ø No new operators can be created
Ø Associativity of an operator can be changed

The input/output streams; cin and cout are ____


Ø Operators
Ø Functions
Ø Objects
Ø Structures

dec, hex, oct are all __________


Ø Member functions
Ø Objects of input/output streams
Ø Parameterized manipulators
Ø Non-parameterized manipulators (Page 435)

Where we can include a header file in the program?


Ø any where (Page 270)
Ø in start
Ø at the end
Ø none of the given options.

While developing a program; sould we think about the user interface? //handouts main reusability hay..us ki
yahan option hi nahi hay
Yes No

A character is stored in the memory in _________


byte
integer
string
None of the given

These functions seekg() and seekp() requires an argument of type ____________to let them how many bytes
to move forward or backward.
int
short
long
double

dereferencing operator is represented by _______


*
+

None of the given

______________ transfers the executable code from main memory to hard disk.
Loader
Debugger
Compiler
Linker

When the logical operator OR (||) combine two expressions exp1 and exp2 then the result will be false only,
//bitwise “or” applies here….
When both exp1 and exp2 are true
When both exp1 and exp2 are false
When exp1 is true and exp2 is false
When exp1 is false and exp2 is true

Suppose we have int y[10]; To access the 4th element of the array we write_________
y[4];
y[3];
y[2];
none of given

We have opened a file stream myfile for reading (getting), myfile.tellg () gives us the current get position of
the file pointer. It returns a whole number of type___________
long
int
short
double

ofstream is used for________


Input file stream
Output file stream
Input and output file stream
All of the given

In C/C++ the string constant is enclosed …………….


► In curly braces
► In small braces
► In single quotes
► In double quotes

The size of int data type is


► 1 bytes
► 2 bytes
► 3 bytes
► 4 bytes
In Flow chart process is represented by
► Rectangle
► Arrow symbol
► Oval
► Circle
If the break statement is missed in switch statement then
► The compiler will give error
► This may cause a logical error
► No effect on program
► Program stops its execution

When we are using const keyword with a variable x then initializing it at the time of declaration is,
► Must
► Optional
► Not necessary
► A syntax error

Which of the following is the correct way to assign an integer value 5 to element of a matrix say ‘m’ at second
row and third column?
► m[2][3] = 5 ;
► m[3][2] = 5 ;
► m[1][2] = 5 ;
► m[2][3] = ‘5’;

How many total elements must be in two-dimensional array of 3 rows and 2 columns?
►4
►5
►6
►7

Which of the following is the correct statement for the following declaration?
const int *ptr.
►ptr is a constant pointer
►ptr is constant integer pointer
►ptr is a constant pointer to int
►ptr is a pointer to const int

C is a/an ______ language


►low level
►object based
►object oriented
►function oriented

The variables having a name, type and size are just like empty boxes.
►False
►True

What's wrong with this for loop?


for (int k = 2, k <=12, k++)
► the increment should always be ++k
► the variable must always be the letter i when using a for loop
► there should be a semicolon at the end of the statement
► the commas should be semicolons
Most efficient method of dealing with structure variables is to define the structure globally
►True
►False

Syntax of union is identical to ______


►Structure
►Class
►Function
►None of the given options

Compiler is a
► System software
► Application Software
► Driver
► Editor

Operating System is
► An application software
► System Software
► Computer Language
► Interpreter

Which one is the correct syntax for defining an identifier PI with preprocessor directive?
► #define PI 3.1415926;
► #define PI 3.1415926
► #define PI = 3.1415926 ;
► #define PI = 3.1415926

Character strings are arrays of characters that can store


► Only one character
► Limited number of characters
► Number of characters specified.
► None of the given option

Missing semicolon ‘;’ at the end of C++ statement is


► Logical error
► Syntax error
► Runtime error
► None of the given options

An array stores the numbers into consecutive memory locations.


► True
► False

The template functions do NOT promote the code reuse


► True
► False

What will be the correct syntax for initialization of pointer ptr of type int with variable x?
► int ptr = &x ;
► int ptr = x ;
► int *ptr = &x ;
► int ptr* = &x ;

Which of the following function calling mechanism is true for the function prototype given below?
float func(float &);
► Call by value
► Call by reference using pointer
► Call by reference using reference variable
► None of the given options

Which of the following object(s) will call the member operator function within the statement given below?
obj1=obj2+obj3;
► Object obj1
► Object obj2
► Object obj3
► Any of the object

The static data members of a class will be ________


► shared by objects
► created for each object
► initialized within class
► initialized within main function

The region of memory, available for allocation at run time in C language is called ________ memory whereas
in C++ language is called as ________________.
► Heap, Stack
► Stack, Free Store
► Heap, Free Store
► None of above

A variable which is defined inside a function is called


► Automatic variable
► Global variable
► Functional variable
► None of the given option

The default copy constructor provides member wise assignment.


► True
► False

To avoid dangling reference, always return the reference of a local variable from a function.
► True
► False

Analysis is the -------------- step in designing a program.


► Last
► Middle
► Post Design
► First

"delete" operator is used to return memory to free store, which is allocated by the "new" operator.
► True
► False
What does 5 ^ 6 , evaluate to in decimal where ‘^’ is Exclusive OR operator?
►1
►2
►3
►4

If constructor contains a return statement in its body then compiler will give __________ check
► No error
► Syntax error
► Logical error
► Run time error
As the constructor does not return any thing, so it has no return type. It means that the body of the
construct function cannot have any return statement. Otherwise, the compiler will give a syntax error. P
# 322

We can use New keyword inside of Class Constructor.


►True
►False

Which of the following data type(s) can operate on modulus operator ‘%’?
► float, int
► float, double
► int
► char

Array is passed by value to a function by default.


►True
►False

What will be the correct syntax to initialize all elements of two-dimensional array to value 0?
►int arr[2][3] = {0,0} ;
►int arr[2][3] = {{0},{0}} ;
►int arr[2][3] = {0},{0} ;
►int arr[2][3] = {0} ;

When an operator function is define as member function then operand on the left side of operator must be an
object.
►True
►False

When an operator function is define as member function for a Unary operator then the number of argument it take is/are,

►Zero

►One
►Two
►N arguments

break statement can be used outside a loop or switch statement.


►True
►False

The keyword_______ is used to return some value from a function.


►return
►break
►continue
►goto

Every data member or function inside the structure is ___ by default whereas everything declared inside a
class is ____ by default.
►private, public
►public, private
►private, protected
►public, protected

Which of the following is true for the C++ statement given below?
int &ref = val ;
►It creates a synonym for variable ‘val’
►It creates an alias for variable ‘val’
►It’s a new name for variable ‘val’
►All of the given options

The input/output streams cin and cout are ________ therefore have _______.
► Structures, function
► Objects, member functions
► Functions, objects
► None of the given options

new and delete keywords are _____________ in C++ language.


► Built-in- Function
► Operators
► Memory Allocation Function
► None of the given options

A constructor that will create a new object with a full copy of the other object, is copy is known as
___________
►deep copy
►shallow copy
►constructor copy
►none of the options

setw is a parameterized manipulator.


►True
► False

new and delete operators cannot be overloaded as member functions.


► True
► False

Such function which do not return any value are called:


► int
► void
► double
► float

The correct syntax of do-while loop is,


► (condition ) while; do { statements; };
► { statements; } do-while ();
► while(condition); do { statements; };
► do { statements; } while (condition);

Which of the following can not be a variable name?


area _area 10area area2

Let assume if s is an object of the class then function is implemented as ___________


► Member function
► Non-member function
► Binary operator function
► None of the given options
► None of the given options
Consider the following code segment. What will be the output of the following program?
int func(int) ;
int num = 10 ;
int main(){
int num ;
num = 5 ;
cout << num ;
cout << func(num) ;
}
int func(int x){
return num ;
}
► 5, 5
► 10, 5
► 5, 10
► 10, 10

Consider the following code segment. What will be the output of this code segment?As
arrays starts from 0 index………at 1st position is 3………n at position 4th is 5…
……5-3=2
int arr[6] = {2, 3, 7, 4, 5, 6} ;
int *ptr1 =&arr[1] ;
int *ptr2 = &arr[4] ;
cout << (ptr2-ptr1) ;
►3
►9
► 12
►2

Consider the following code segment.


class M {
public:
M &operator+(const M &);
...
};
p+q //code of line implies that p.operator+(q)
...

Let assume if p and q are class objects then function is implemented as _______
► Member function
► Non-member function
► Friend function
► None of the given options

Consider the following code segment


class M {
friend int operator!(const M &);
...
};
!s // code of line implies that operator!(s)
...

Consider the following code segment. What will be the output of following code?
Int addValue (int *a){
int b = (*a) + 2;
return b ;
}
main () {
int x =6 ;
cout << x << “,” ;
cout << addValue(&x) << “,” ;
cout << x ;
}
► 6,8,6
► 6,6,8
► 6,8,8
► 6,6,6

For which values of the integer _value will the following code becomes an infinite loop?
int number=1;
while (true) {
cout << number;
if (number == 3) break;
number += integer_value; }
► any number other than 1 or 2
► only 0
► only 1
► only 2

What will be the output of the following statement?


cout << setbase(16) << 52 ;
Ø 74
Ø 52
Ø 34
Ø 64

Let suppose
Union intorDouble{
Int ival;
Double charvar;
};
main(){
intorDouble VAZ;
int size ;
size = sizeof(VAZ);
}

What will be the value of variable "size", if int occupies 4 bytes and double occupies 8 bytes?
Ø2
Ø4
Ø8
Ø 12

You might also like