Short Questions on C++

I

irshadjat

Question No.01
Which of the following is true about streams?

A. It is a sequence of bytes
B. It is an ordered sequence
C. All bytes can go through the stream simultaneously
D. Bytes that enters first into the stream will go out at last
0 A only
0 C only
0 A and B
0 A and D



Question No.02
Consider the following code segment.
1. String s1, s2;
2. s1 = s2;

Which of the following will be called while executing code at line 2 ?

0 Copy constructor
0 Default constructor
0 Assignment operator
0 Parameterized constructor


Question No.03
What is the difference between cout and cerr ?


0 cout is unbuffered output and cerr is buffered output
0 cout is standard output and cerr is not a standard output
0 cout is not a standard output and cerr is standard output
0 cout is buffered output and cerr is unbuffered output

Question No.04
If text is a pointer of type String then what will be the
functionality of following statement?
text = new String [5];

0 Creates array of 5 Staring objects statically
0 Creates array of 5 String objects dynamically
0 Creates array of pointers to String objects
0 Creates a String object



Question No.05
When an operator function is defined as member function for a Unary
operator then how many argument it will take?

0 Zero
0 One
0 Two
0 More then two arguments


Question No.06
Which of the following is the only operator that the compiler
overloads for user define data type?
0 Assignment (=)
0 Plus (+)
0 Minus (-)
0 Equal (==)

Question No.07
If we do not write our own assignment operator then which of the
following problem may occur?
0 Memory Leak
0 Dangling pointer
0 NULL pointer
0 Unreferenced memory

Question No.08
What functionality the following program is performing?

#include <iostream.h>

int main(0
{
const int SIZE = 80;
char buffer[SIZE];
cout <<” Enter a sentence : “<<endl;
cin.read (buffer, SIZE);
cout << “ The sentence entered is : “ <<endl;
cout.write(buffer, cin.gcount());

return 0;
}

0 read and write member functions of cin and cout objects are used to
read a sentence from the keyboard and then print it on the screen.
0 read and put member functions of cin and cout objects are used to
read a sentence from the key board and then print it on the screen.
0 get and write member functions of cout and cin objects are used to
read a sentence from the keyboard and then print it on the screen.
0 read and write member functions of cin and cout objects are used to
read a word from the key board and then print it on the screen.

Question No.09
If we have a program that writes the output data (numbers) to the disc
and if we collect the output data and write it on the disc in one
write operation instead of writing the numbers one by one.
In the above situation the area where we gather the number is called

0 Heap
0 Stack
0 Buffer
0 Cache


Question No.10
Consider the following code segment.
String str[5] = {String(“Programming”), String(“CS201”)};
0 Default constructor will be called for all 5 objects
0 Parameterized constructor will be called for all 5 objects
0 Parameterized constructor will be called for first 2 objects
0 Default constructor will be called for first 2 objects
 
J

James Kanze

On Jul 23, 8:19 am, (e-mail address removed) wrote:

Interesting test (but I'll let you do your own homework). There
are several problems, however:

[...]
Question No.03
What is the difference between cout and cerr ?
0 cout is unbuffered output and cerr is buffered output
0 cout is standard output and cerr is not a standard output
0 cout is not a standard output and cerr is standard output
0 cout is buffered output and cerr is unbuffered output

This one depends a lot on context; if you've called setbuf on
one of the streams, or changed its streambuf, for example, all
bets are off. Without such subtilities, however, none of the
above are true.

[...]
Question No.07
If we do not write our own assignment operator then which of the
following problem may occur?
0 Memory Leak
0 Dangling pointer
0 NULL pointer
0 Unreferenced memory

This one has several correct answers (two or three, depending
one what the last choice means).
Question No.08
What functionality the following program is performing?
#include <iostream.h>
int main(0
{
const int SIZE = 80;
char buffer[SIZE];
cout <<? Enter a sentence : ?<<endl;
cin.read (buffer, SIZE);
cout << ? The sentence entered is : ? <<endl;
cout.write(buffer, cin.gcount());
return 0;
}
0 read and write member functions of cin and cout objects are used to
read a sentence from the keyboard and then print it on the screen.
0 read and put member functions of cin and cout objects are used to
read a sentence from the key board and then print it on the screen.
0 get and write member functions of cout and cin objects are used to
read a sentence from the keyboard and then print it on the screen.
0 read and write member functions of cin and cout objects are used to
read a word from the key board and then print it on the screen.

And none of the above are true.
 
C

Christian Hackl

Question No.08
What functionality the following program is performing?

#include <iostream.h>

Perhaps none, because chances are your compiler will reject it. The
correct form is <iostream>.
 
M

Matthias Buelow

Question No.01
Which of the following is true about streams?

A. It is a sequence of bytes
B. It is an ordered sequence
C. All bytes can go through the stream simultaneously
D. Bytes that enters first into the stream will go out at last
0 A only
0 C only
0 A and B
0 A and D

C only.
Question No.02
Consider the following code segment.
1. String s1, s2;
2. s1 = s2;

Which of the following will be called while executing code at line 2 ?

0 Copy constructor
0 Default constructor
0 Assignment operator
0 Parameterized constructor

Either the default constructor or the parameterized constructor,
depending on whether you're using Visual Studio or gcc.
Question No.03
What is the difference between cout and cerr ?


0 cout is unbuffered output and cerr is buffered output
0 cout is standard output and cerr is not a standard output
0 cout is not a standard output and cerr is standard output
0 cout is buffered output and cerr is unbuffered output

Answer 3 is correct.
Question No.04
If text is a pointer of type String then what will be the
functionality of following statement?
text = new String [5];

0 Creates array of 5 Staring objects statically
0 Creates array of 5 String objects dynamically
0 Creates array of pointers to String objects
0 Creates a String object

The first answer, obviously.
Question No.05
When an operator function is defined as member function for a Unary
operator then how many argument it will take?

0 Zero
0 One
0 Two
0 More then two arguments

Of course it's more than two arguments, often 4 or 5, depending on
whether the "that" pointer is also passed.
Question No.06
Which of the following is the only operator that the compiler
overloads for user define data type?
0 Assignment (=)
0 Plus (+)
0 Minus (-)
0 Equal (==)

It's "==", for which the compiler will automatically generate code to
compare a hashsum of the memory areas occupied by the objects in question.
Question No.07
If we do not write our own assignment operator then which of the
following problem may occur?
0 Memory Leak
0 Dangling pointer
0 NULL pointer
0 Unreferenced memory

Dangling pointer. There're a couple other problems, such as possibly
preventing the system from deallocating a process' CPU time when it
exits but these are rather system-dependent.
Question No.08
What functionality the following program is performing?

#include <iostream.h>

int main(0
{
const int SIZE = 80;
char buffer[SIZE];
cout <<” Enter a sentence : “<<endl;
cin.read (buffer, SIZE);
cout << “ The sentence entered is : “ <<endl;
cout.write(buffer, cin.gcount());

return 0;
}

It prints the length of the sequence it read from cerr.
0 read and write member functions of cin and cout objects are used to
read a sentence from the keyboard and then print it on the screen.
0 read and put member functions of cin and cout objects are used to
read a sentence from the key board and then print it on the screen.
0 get and write member functions of cout and cin objects are used to
read a sentence from the keyboard and then print it on the screen.
0 read and write member functions of cin and cout objects are used to
read a word from the key board and then print it on the screen.

This is a really hard one and it's difficult to decide. I'd go with the
first answer.
Question No.09
If we have a program that writes the output data (numbers) to the disc
and if we collect the output data and write it on the disc in one
write operation instead of writing the numbers one by one.
In the above situation the area where we gather the number is called

0 Heap
0 Stack
0 Buffer
0 Cache

On the stack, of course.
Question No.10
Consider the following code segment.
String str[5] = {String(“Programming”), String(“CS201”)};
0 Default constructor will be called for all 5 objects
0 Parameterized constructor will be called for all 5 objects
0 Parameterized constructor will be called for first 2 objects
0 Default constructor will be called for first 2 objects

Obviously the default constructor will be called for all 5 objects.

These were pretty easy. Good luck. Hope that helps.
 
P

Pascal J. Bourguignon

Matthias Buelow said:
Of course it's more than two arguments, often 4 or 5, depending on
whether the "that" pointer is also passed.

Not forgetting these and those.

int SomeClass::someMethod(SomeClass* that){
return((this->value+that->value)*these->factors/those->denominators);
}
 
P

Pascal J. Bourguignon

Matthias Buelow said:
On the stack, of course.

I think you're wrong on this one. Since the numbers are not written
one by one, this cannot be a Stack. That must be a Heap, all the
numbers being dumped at once.

These were pretty easy. Good luck. Hope that helps.

Right, good luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top