0% found this document useful (0 votes)
225 views16 pages

Mcqs Cs 201

vu CS 201 MCQS

Uploaded by

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

Mcqs Cs 201

vu CS 201 MCQS

Uploaded by

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

…………. function is used to determine the current location while reading a file.

A. tellp()
B. tellg()
C. seekp()
D. seekg()
…………. operator can be used for masking of flags.

A. ^
B. &&
C. ||
D. >>

What will be the output of the following code?

int main(){
int i = 20;

for(int i=1;i<10;i++);
cout<<i;

return 0;
}

A. 10
B. 20
C. 9
D. 1

What will be the output of the following code?

int main() {
change();
return 0;
}
int change (int a=12){
int b=12;
a = a + b;
cout<<a++;
}

A. 12
B. 24
C. 25
D. 26
While handling files in C++, the default mode of “ifstream” library for opening file is.
A. ios::ate
B. ios::out
C. ios::in
D. ios::app
In C++, “getline()” function is a built-in function that allows accepting and reading.
A. Single line
B. Multiple lines
C. Single and Multiple lines
D. Only multiword input
Which one of the following is correct definition of structure?
A. struct Student{char name[30]}
B. struct Student {char name[30];}
C. struct Student {char name[35];};
D. struct {char name[30]};

struct book {
char title[20];
};

int main(){
book * sptr;
}

From the above code the correct way to access the data member title of the structure book
through pointer is?

A. sptr.title
B. sptr:title
C. sptr->title
D. .sptr*title

What will be the output of the following program?

#include <iostream>
#define LIMIT 3

int main()
{
for (int i = 2; i < LIMIT; i++) {
std::cout << i* LIMIT << "\t";
}
return 0;
}
A. 6
B. 2 3 6
C. 3
D. 9
The proper way of defining a macro is.
A. #define SIZE 5;
B. #define SIZE 5
C. Set SIZE 5;
D. #set SIZE 5

In C++, dynamic memory allocation in done on _____ memory.

A. Static
B. Stack
C. Heap
D. Hard Disk

Which of the following is not an acceptable class specifier?


A. public
B. private
C. protected
D. pointer
Question No: 13 (Marks: 01) - Please choose the correct option

_____ is another name for a class's data members.

A. Attribute
B. Method
C. Instance
D. Dimensions

Question No: 14 (Marks: 01) - Please choose the correct option


In C++, class data members are generally kept as ______.
A. public
B. private
C. protected
D. static

Question No: 15 (Marks: 01) - Please choose the correct option

To declare the friend function, which keyword is used?


A. Friend
B. FRIEND
C. FrienD
D. friend

Question No: 16 (Marks: 01) - Please choose the correct option

In C++, which of the following operator cannot be overloaded?

A. +
B. -
C. /
D. ->

Question No: 17 (Marks: 01) - Please choose the correct option

A class includes both data members as well as functions to manipulate the data. These functions
are called ___________.

A. Member functions
B. Constant functions
C. Rational functions
D. Memory functions

Question No: 18 (Marks: 01) - Please choose the correct option


Which of the following is known as an instance of a class?

A. Data member
B. Constructor
C. Member function
D. Object

Question No: 19 (Marks: 01) - Please choose the correct option

In friend function, which operator is utilized to access members of a class using class objects.

A. ::
B. +
C. *
D. .

Question No: 20 (Marks: 01) - Please choose the correct option

Which of the following is the correct way of referring a data member “buf” of a class name
“String”? Consider “buf” data member declared as a character pointer.

A. buf;
B. this->buf;
C. *(this).buf;
D. *this.buf

Question No: 21 (Marks: 01) - Please choose the correct option

In C++, which of the following operator can be overloaded?

A. sizeof
B. ?:
C. ::
D. %

Question No: 22 (Marks: 01) - Please choose the correct option

When a unary operator is overloaded and is a member of a class, how many arguments need to
be passed explicitly when it is called?

A. Zero
B. One
C. Two
D. Three

Question No: 23 (Marks: 01) - Please choose the correct option

What will be the output of following program in C++?

#include<iostream>
using namespace std;
class A
{
int a;
public:
A(int x):a(x){}
int geta() {return a;}
};
int main ()
{
A M(10),N(20);
N = M;
cout<<N.geta();
return 0;
}

A. 20
B. 10
C. 30
D. 15

Question No:24 (Marks: 01) - Please choose the correct option


Which of the following manipulators “Terminate a string with NULL”?

A. endl
B. flush
C. ends
D. ws

Question No: 25 (Marks: 01) - Please choose the correct option

What will be the output of following code snippet written in C++?


int main(){
double var = 3.14362987;
cout<< setprecision(4) << var;
}

A. 3.144
B. 3.143
C. 3.1436
D. 3.145

Question No: 26 (Marks: 01) - Please choose the correct option

Which of the following is not a format state flag?

A. ios::dec
B. ios::showpoint
C. ios::showcause
D. ios::right

Question No: 27 (Marks: 01) - Please choose the correct option

Which of the following is not a recommended way to use a copy constructor?

A. Explicit call to the copy constructor


B. Using “=” operator
C. In passing by value
D. In passing by reference

Question No: 28 (Marks: 01) - Please choose the correct option

If we press the key 1 from the keyboard to store it in integer i, the digit 1 travels as a(an)
_________ but stored as number inside i.

A. integer
B. character
C. float
D. double

Question No: 29 (Marks: 01) - Please choose the correct option

In C++, for every stream, there should be ________.

A. Template and class


B. Source and destination
C. Function and operator
D. Structure and Union

Question No: 30 (Marks: 01) - Please choose the correct option

In C++, whenever have an “&” ampersand symbol appears on right hand side of an “=”
assignment operator, it is taken as ______ of an object.

A. Pointer
B. Reference
C. Address
D. Function

Question No: 31 (Marks: 01) - Please choose the correct option


While writing nested classes in C++, no memory is allocated for it unless a/an _______ of it is
created.

A. Function
B. Instance
C. Class
D. Operator

Question No: 32 (Marks: 01) - Please choose the correct option

In C++, which one from the following errors can be encountered when dealing with references.

A. Memory Leak
B. Dangling Reference
C. Static Reference
D. Global Reference

Question No: 33 (Marks: 01) - Please choose the correct option

In C++, operator overloading is quite similar to _______.

A. Macros.
B. Inline function
C. Function overloading
D. Object Creation

Question No: 34 (Marks: 01) - Please choose the correct option

Considering knowledge of using a friend functions in C/C++, choose which rule is applicable on
friend functions?

A. private members cannot be accessed from anywhere


B. protected members cannot be accessed from anywhere
C. protected and private members can be accessed from outside the class
D. protected and private members cannot be accessed from outside the class

Question No: 35 (Marks: 01) - Please choose the correct option


The correct syntax for writing a template ‘class student’ of type ‘T’ is _____.
A. template <class T> class student { …. };
B. template <Class T> Class student{ …. };
C. Template <class T> class student { …. };
D. template <class student > class T { …. };

Question No: 36 (Marks: 01) - Please choose the correct option

In C/C++, the array index number for representing last element of an array of size 10 is _____.
A. 5
B. 7
C. 9
D. 11

Question No: 37 (Marks: 01) - Please choose the correct option

Trace the output of the following code segment.


int main(){
int arr[2][3]= {{1, 2, 3}, {4, 5, 6}}
cout<<arr[1][1];

A. 2
B. 4
C. 5
D. 6

Question No: 38 (Marks: 01) - Please choose the correct option

What will be the output of the given code segment?


int arr[]={2,5,6,8,9,10,6,3,1};
int * ptr= &arr[1];
cout<<*(ptr+4);

A. 6
B. 10
C. 3
D. 1

Question No: 39 (Marks: 01) - Please choose the correct option

What will be the output of the given code segment?

int arr[]={2,5,6,8,9,10,6,3,1};
int * ptr= &arr[3];
cout<<*(ptr+4);

A. 10
B. 6
C. 3
D. 5

Question No: 40 (Marks: 01) - Please choose the correct option

Which one of the following is not a keyword and can be used as an identifier in C/C++?
A. friends
B. template
C. this
D. new

Question No: 41 (Marks: 03)

Determine the number of iterations the following loop will run.

int op, lim, k;


op = 6;
lim = 0;
while (k <= 60) {
k = op << lim;
lim += 1;
}

Question No: 42 (Marks: 03)

What is the masking operator? Write the code snippet and determine the output of expression
which masks a variable int x = 100; with int m = 50;

Question No: 40 (Marks: 03)

What will be output of the following code segment?

class Output{
private:
int a,b,c;
public:
Output(){
a = 8;
b = 4;
c = 0;
}
void Display(){
c=a/b;
cout <<a<<"\n"<<b<<"\n"<<c;
}
};
int main() {
Output ob;
ob.Display();
return 0;
}

Question No: 44 (Marks: 03)

Name the types of constructor used in C++.

Question No: 45 (Marks: 03)


Write the keywords used for auxiliary input output stream and printer output stream in DOS.

Question No: 46 (Marks: 05)

What will be output of the following program?

#include <iostream>
using namespace std;
int main () {

double x = 123.4;
cout.precision(4);
cout<< scientific;
cout<< x << endl;
return 0;

Question No: 47 (Marks: 05)

What will be the output of the following code written in C++. (Assuming memory is successfully
allocated in both calls)

int main(){
int *ptr, sum=0, i=0, n=3;

ptr = (int *) malloc (n * sizeof(int));

if (ptr==NULL) {
cout<<"Memory allocation is not successful";
return 1;
}
while (i<=n) {
*(ptr+i) = i;
i++;
}

n=5;

ptr = (int *) realloc (ptr, n * sizeof(int));


if (ptr == NULL){
cout<<"Memory allocation is not successful";
return 1;
}
for (int j = 0;j < = n; j++){
*(ptr + j ) = j;
sum +=*( ptr + j);
}
cout<<"sum="<<sum;
free(ptr);
return 0;
}

Question No: 48 (Marks: 05)

Trace the output of the following code.

class first
{
friend void add(first *, int);
private:
int variable;
public:
void print()
{
cout << "Variable = " <<variable<<endl;
}
first();
};
first::first()
{
variable = 0;
}
void add(first *x, int y){
x->variable += y;
}

int main(){
first z;
z.print();
add(&z, 10);
z.print();
}
Question No: 49 (Marks: 05)

Write the C++ syntax to create and delete a dynamic array using new and delete operator.

Question No: 50 (Marks: 05)


Carefully read and analyze the following code and determine its output.

class One {
public:
One(){
cout << "Class One Constructor" << endl;
}
~One(){
cout << "Class One Destructor" << endl;
}
};
class Three {
private:
One one;
public:
Three() {
cout << "Class Three Constructor" << endl;
}
~Three(){
cout << "Class three Destructor" << endl;
}

};
class Two {

private:
Three three;
public:
Two(){
cout << "Class Two Constructor" << endl;
}
};

int main()
{
Two two;
return 0;
}

You might also like