Connecting Tech Pros Worldwide Forums | Help | Site Map

Short Questions on C++

irshadjat@gmail.com
Guest
 
Posts: n/a
#1: Jul 23 '08
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

James Kanze
Guest
 
Posts: n/a
#2: Jul 23 '08

re: Short Questions on C++


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:

[...]
Quote:
Question No.03
What is the difference between cout and cerr ?
Quote:
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.

[...]
Quote:
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).
Quote:
Question No.08
What functionality the following program is performing?
Quote:
#include <iostream.h>
Quote:
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());
Quote:
return 0;
}
Quote:
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:james.kanze@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
Christian Hackl
Guest
 
Posts: n/a
#3: Jul 23 '08

re: Short Questions on C++


irshadjat@gmail.com wrote:
Quote:
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
Matthias Buelow
Guest
 
Posts: n/a
#4: Jul 23 '08

re: Short Questions on C++


irshadjat@gmail.com wrote:
Quote:
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.
Quote:
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.
Quote:
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.
Quote:
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.
Quote:
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.
Quote:
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.
Quote:
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.
Quote:
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.
Quote:
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.
Quote:
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.
Quote:
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.
Pascal J. Bourguignon
Guest
 
Posts: n/a
#5: Jul 23 '08

re: Short Questions on C++


Matthias Buelow <mkb@incubus.dewrites:
Quote:
Quote:
>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__
Pascal J. Bourguignon
Guest
 
Posts: n/a
#6: Jul 23 '08

re: Short Questions on C++


Matthias Buelow <mkb@incubus.dewrites:
Quote:
Quote:
>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.

Quote:
These were pretty easy. Good luck. Hope that helps.
Right, good luck!

--
__Pascal Bourguignon__
red floyd
Guest
 
Posts: n/a
#7: Jul 23 '08

re: Short Questions on C++


On Jul 22, 11:19*pm, irshad...@gmail.com wrote:
Quote:
[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

Victor Bazarov
Guest
 
Posts: n/a
#8: Jul 23 '08

re: Short Questions on C++


irshadjat@gmail.com wrote:
Quote:
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
Closed Thread