469,282 Members | 1,921 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Short Questions on C++

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
Jul 23 '08 #1
7 7495
On Jul 23, 8:19 am, irshad...@gmail.com 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.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 23 '08 #2
ir*******@gmail.com wrote:
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>.
--
Christian Hackl
Jul 23 '08 #3
ir*******@gmail.com wrote:
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.
Jul 23 '08 #4
Matthias Buelow <mk*@incubus.dewrites:
>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.
Not forgetting these and those.

int SomeClass::someMethod(SomeClass* that){
return((this->value+that->value)*these->factors/those->denominators);
}
--
__Pascal Bourguignon__
Jul 23 '08 #5
Matthias Buelow <mk*@incubus.dewrites:
>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.
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!

--
__Pascal Bourguignon__
Jul 23 '08 #6
On Jul 22, 11:19*pm, irshad...@gmail.com wrote:
[do my homework redacted]
The answers to all your questions may be found in the FAQ, in
particular, FAQ 5.2.

http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

Jul 23 '08 #7
ir*******@gmail.com wrote:
Question No.01
Which of the following is true about streams?
[..]
Surprising as it may sound, but all your questions are answered in the
FAQ. See question 5.2.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 23 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by varois83 | last post: by
8 posts views Thread by frizzle | last post: by
8 posts views Thread by cody | last post: by
3 posts views Thread by KvS | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.