By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,848 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

Correcting answers

P: n/a
Can any one correct these true and false answer for me? I did not but I
don't know if they are all corrected. THanks

True. In C++, resersed words the same as predefined identifiers.

False. An indentifier can be any sequence of digits, leters, and the
underscore.

True. When trying to store a double value in an int variable, the double
value is rounded to the nearest interger.

False. An if statement cannot be nested in a switch statement, but a switch
statement can be nested in an if statement.

True. The execution of a break statement in a while loop terminates the
loop.

True. A function definition consists of the function heading and the body of
the function.

True. Parameters allow the programmer to use different values each time the
functions is called.

False. The execution of the return statement in a user-defined function
terminates the program.

True. It is not necessary to specify the names of formal parameters in a
function prototype.

False. The return statement

Return x +1;

First returns the values of x and then increments the values of
x.

True. The following return statement return the value 10.

Return 10,16;

True. The following statement in a value-returning function is legal.(
assume that all variables are properly declared)

If (x%==0)

Return x;

Else

Return x +1;

True. Given the function prototype

Float test();

The statement

Cout<<test;

Is legal because the function test has no parameters.

True. Given the function prototype

Double testAlpha (int u, char v, double t);

The following statement is legal.

Cout<<testAlpha(5, 'A', 2);

False. If a formal parameters is a value parameter and the corresponding
actual parameters is a variable, the actual parameter can be modified.

False. If an ampersand, & is attached to the data type of a formal
parameter, the corresponding actual parameter must be a variable.

True. A value parameter only changes its own content without changing the
value of the actual parameter.

True. A variable name can be passed to a value parameter.

False. The corresponding actual parameter for a reference parameter can be
any expression

True. Any parameter the receives a value and also sends a value outside the
function must be declared as reference parameter.

True. If a formal parameter is a reference parameter, the corresponding
actual parameter must be a varialble

True. The pass by value mechanism must be used if the calling code is to
receive values back from the function.

True. A variable declared outside of every block is called a global
variable.

True. In a program global constants have no side effects.

False. The scope of a formal parameter and the scope of a local variable
declared in the outer block of a function body is the same

True. In C++, function definitions cannot be nested, that is, the definition
of one function cannot be enclosed in the body of another function.

True. A static variable works the same way as global variable because memory
for the static variables remains allocated during program execution.

True. The following is a legal C++ function definition

Void funcTest(int& u, double& v);

{

Cout<<u<<" "<<v<<endl;

}

False. The output of the C++ code

Int alpha =5;

Int beta=10;

Alpha = alpha +5;

{

Int alpha;

Alpha=20;

beta= beta +5;

}

Cout<<alpha<<" "<<beta<<endl;

Is: 10 15

True. In C++ , when declaring an array as a formal parameter, the size of
the array must be specified within square brackets.

True. The word const is used before the array declaration in a function
heading to prevent the function from modifying the array.

False. A struct can be passed as a parameter to a function by value or by
reference.

True. A function cannot return a value of a type struct

True. The Address operator is a urary operator that returns the address of
its operand.

True. Any number can be directly assigned to a pointer variable.
Dec 12 '05 #1
Share this Question
Share on Google+
22 Replies


P: n/a
Richard wrote:
Can any one correct these true and false answer for me? I did not but I
I don't understand your statement "I did not but I don't know ..."
don't know if they are all corrected. THanks
[...]


And, no, we don't do homeworks.

V
Dec 12 '05 #2

P: n/a

"Richard" <no********@yahoo.com> wrote in message
news:ja******************************@comcast.com. ..
Can any one correct these true and false answer for me? I did not but I
don't know if they are all corrected. THanks

True. In C++, resersed words the same as predefined identifiers.

False. An indentifier can be any sequence of digits, leters, and the
underscore.


1) How coud we possibly know if the answers are correct, when you haven't
given the questions???

2) If this is some kind of homework, we don't do that here.

3) A lot of what you've written is badly misspelled and/or makes no sense.
This first "answer" is a good example: "resersed words the same as
predefined identifiers". What does that mean?

-Howard
Dec 12 '05 #3

P: n/a

"Howard" <al*****@hotmail.com> wrote in message
news:eT********************@bgtnsc04-news.ops.worldnet.att.net...

"Richard" <no********@yahoo.com> wrote in message
news:ja******************************@comcast.com. ..
Can any one correct these true and false answer for me? I did not but I
don't know if they are all corrected. THanks

True. In C++, resersed words the same as predefined identifiers.

False. An indentifier can be any sequence of digits, leters, and the
underscore.


1) How coud we possibly know if the answers are correct, when you haven't
given the questions???


Hmm... I guess those _are_ the questions, and the answers are the true/false
you give before them? Very odd way of listing the questions and answers in
that case...

-Howard

Dec 12 '05 #4

P: n/a

Richard wrote:
Can any one correct these true and false answer for me? I did not but I
don't know if they are all corrected. THanks


<snip>

C++ is a case-sensitive language, but your post breaks the rules
several times. For example a return statement must use a lower-case
'r'.

Dec 12 '05 #5

P: n/a
Earl Purple wrote:
Richard wrote:
Can any one correct these true and false answer for me? I did not but I
don't know if they are all corrected. THanks

<snip>

C++ is a case-sensitive language, but your post breaks the rules
several times. For example a return statement must use a lower-case
'r'.


Actually it must use *two* lower-case 'r's.

V
Dec 12 '05 #6

P: n/a
On Mon, 12 Dec 2005 12:46:10 -0500, Victor Bazarov
<v.********@comAcast.net> wrote:
Earl Purple wrote:
Richard wrote:
Can any one correct these true and false answer for me? I did not but I
don't know if they are all corrected. THanks

<snip>

C++ is a case-sensitive language, but your post breaks the rules
several times. For example a return statement must use a lower-case
'r'.


Actually it must use *two* lower-case 'r's.

V


So THAT'S why my source wouldn't compile:

retuRn someValue;
}

DOH!
Dec 12 '05 #7

P: n/a

"Richard" <no********@yahoo.com> wrote in message
news:ja******************************@comcast.com. ..
Can any one correct these true and false answer for me? I did not but I
don't know if they are all corrected. THanks

True. In C++, resersed words the same as predefined identifiers.
FALSE

False. An indentifier can be any sequence of digits, leters, and the
underscore.
FALSE

True. When trying to store a double value in an int variable, the double
value is rounded to the nearest interger.
TRUE

False. An if statement cannot be nested in a switch statement, but a switch statement can be nested in an if statement.
FALSE
True. The execution of a break statement in a while loop terminates the
loop.
TRUE

True. A function definition consists of the function heading and the body of the function.
TRUE

True. Parameters allow the programmer to use different values each time the functions is called.
TRUE

False. The execution of the return statement in a user-defined function
terminates the program.
FALSE

True. It is not necessary to specify the names of formal parameters in a
function prototype.
TRUE

False. The return statement


Return x +1;

First returns the values of x and then increments the values of x.
FALSE

True. The following return statement return the value 10.

Return 10,16;

FALSE

True. The following statement in a value-returning function is legal.(
assume that all variables are properly declared)

If (x%==0)

Return x;

Else

Return x +1;

FALSE
True. Given the function prototype

Float test();

The statement

Cout<<test;

Is legal because the function test has no parameters. FALSE
True. Given the function prototype

Double testAlpha (int u, char v, double t);

The following statement is legal.

Cout<<testAlpha(5, 'A', 2);
TRUE

False. If a formal parameters is a value parameter and the corresponding
actual parameters is a variable, the actual parameter can be modified.
FALSE

False. If an ampersand, & is attached to the data type of a formal
parameter, the corresponding actual parameter must be a variable.
TRUE

True. A value parameter only changes its own content without changing the
value of the actual parameter.
TRUE

True. A variable name can be passed to a value parameter.
TRUE

False. The corresponding actual parameter for a reference parameter can be
any expression
FALSE

True. Any parameter the receives a value and also sends a value outside the function must be declared as reference parameter.
FALSE

True. If a formal parameter is a reference parameter, the corresponding
actual parameter must be a varialble

TRUE

True. The pass by value mechanism must be used if the calling code is to
receive values back from the function.
FALSE

True. A variable declared outside of every block is called a global
variable.
TRUE

True. In a program global constants have no side effects.
FALSE

False. The scope of a formal parameter and the scope of a local variable
declared in the outer block of a function body is the same
FALSE

True. In C++, function definitions cannot be nested, that is, the definition of one function cannot be enclosed in the body of another function.
TRUE

True. A static variable works the same way as global variable because memory for the static variables remains allocated during program execution.

FALSE
True. The following is a legal C++ function definition

Void funcTest(int& u, double& v);

{

Cout<<u<<" "<<v<<endl;

} TRUE
False. The output of the C++ code

Int alpha =5;

Int beta=10;

Alpha = alpha +5;

{

Int alpha;

Alpha=20;

beta= beta +5;

}

Cout<<alpha<<" "<<beta<<endl;

Is: 10 15
FALSE

True. In C++ , when declaring an array as a formal parameter, the size of
the array must be specified within square brackets.
TRUE

True. The word const is used before the array declaration in a function
heading to prevent the function from modifying the array.
FALSE

False. A struct can be passed as a parameter to a function by value or by
reference.
FALSE

True. A function cannot return a value of a type struct
FALSE

True. The Address operator is a urary operator that returns the address of
its operand.
TRUE

True. Any number can be directly assigned to a pointer variable.
FALSE

Dec 12 '05 #8

P: n/a
On Mon, 12 Dec 2005 12:52:07 -0500, dave wrote:
True. When trying to store a double value in an int variable, the double
value is rounded to the nearest interger.

TRUE


AFAIK, it rounds towards zero (truncates). So, FALSE.

- Jay
Dec 12 '05 #9

P: n/a
On Mon, 12 Dec 2005 12:52:07 -0500, dave wrote:

"Richard" <no********@yahoo.com> wrote in message
news:ja******************************@comcast.com. ..


True. The execution of a break statement in a while loop terminates the
loop.

TRUE


Usually. But:

while (!done)
{
for (int i = 0; i < 10; ++i)
{
if (i == 3)
break;
}
}

Is the break statement considered "in the while loop"?

True. Given the function prototype

Float test();

The statement

Cout<<test;

Is legal because the function test has no parameters.

FALSE


Perfectly *legal* (mis-casing of "cout" ignored). It prints out the
address of the function test. It will work even if the function has
parameters. (Of course, it will not actually invoke the function in any
case without parens.)


False. If an ampersand, & is attached to the data type of a formal
parameter, the corresponding actual parameter must be a variable.

TRUE


Unless it's const (e.g. "const int &"), in which case it can be bound to a
temporary.


True. If a formal parameter is a reference parameter, the corresponding
actual parameter must be a varialble


TRUE


Same as before - unless it's const.

True. The following is a legal C++ function definition

Void funcTest(int& u, double& v);

{

Cout<<u<<" "<<v<<endl;

}

TRUE


FALSE. The trailing semi-colon on the "funcTest" line results in a syntax
error.


True. In C++ , when declaring an array as a formal parameter, the size of
the array must be specified within square brackets.

TRUE


FALSE.

int main(int argc, char* argv[])
{
}


True. The word const is used before the array declaration in a function
heading to prevent the function from modifying the array.

FALSE


TRUE. (What else would the const do?)


False. A struct can be passed as a parameter to a function by value or by
reference.

FALSE


TRUE.

struct Point { int x, y; }

void myFunc(Point inp, Point& outp);
- Jay
Dec 12 '05 #10

P: n/a
Jay Nabonne wrote:
On Mon, 12 Dec 2005 12:52:07 -0500, dave wrote:

True. When trying to store a double value in an int variable, the double
value is rounded to the nearest interger.


TRUE

AFAIK, it rounds towards zero (truncates). So, FALSE.


It depends on the CPU mode. It is usually programmable as well. IOW,
it's implementation- and system-specific and the default value of the
'round_style' is 'round_toward_zero' for generic 'numeric_limits'
template, but can be 'round_to_nearest' for 'float', as the example on
page 340-341 shows.

V
Dec 12 '05 #11

P: n/a
On Mon, 12 Dec 2005 13:44:36 -0500, Victor Bazarov wrote:
Jay Nabonne wrote:
On Mon, 12 Dec 2005 12:52:07 -0500, dave wrote:

True. When trying to store a double value in an int variable, the double
value is rounded to the nearest interger.
TRUE

AFAIK, it rounds towards zero (truncates). So, FALSE.


It depends on the CPU mode. It is usually programmable as well. IOW,
it's implementation- and system-specific and the default value of the
'round_style' is 'round_toward_zero' for generic 'numeric_limits'
template, but can be 'round_to_nearest' for 'float', as the example on
page 340-341 shows.


That's good to know. Thanks!
Dec 12 '05 #12

P: n/a

Richard wrote:
True. The following return statement return the value 10.

Return 10,16;


FALSE

Spelling error aside (return), the return value will be 16.
Quote from the C++ Standard (2003):

Sect. 5.18 P. 1 - "A pair of expressions separated by a comma is
evaluated left-to-right and the value of the left expression is
discarded."

Cheers,
Andre

Dec 12 '05 #13

P: n/a
Jay Nabonne <ja*********@sonicNOSPAM.com> schrieb:
Float test();
The statement
Cout<<test;
Is legal because the function test has no parameters.

FALSE


Perfectly *legal* (mis-casing of "cout" ignored). It prints out the
address of the function test. It will work even if the function has


So the answer 'FALSE' is right, because it is not legal because of
no parameters, but because of 'missing' parentheses(sp?).
True. The following is a legal C++ function definition

Void funcTest(int& u, double& v);
{
Cout<<u<<" "<<v<<endl;
}

TRUE


FALSE. The trailing semi-colon on the "funcTest" line results in a syntax
error.


Actually, it is the '{' following the ';' which triggers an error.
Up to the ';' it is a forward declaration.
True. The word const is used before the array declaration in a function
heading to prevent the function from modifying the array.

What is an 'array declaration' in a 'function heading'?
FALSE


TRUE. (What else would the const do?)


Give a hint to the compiler, that the function won't.
BTW: you can cast the 'const' away ...

Markus
Dec 12 '05 #14

P: n/a
On Mon, 12 Dec 2005 23:28:09 +0100, Markus Becker wrote:
Jay Nabonne <ja*********@sonicNOSPAM.com> schrieb:
Float test();
The statement
Cout<<test;
Is legal because the function test has no parameters.
FALSE
Perfectly *legal* (mis-casing of "cout" ignored). It prints out the
address of the function test. It will work even if the function has


So the answer 'FALSE' is right, because it is not legal because of
no parameters, but because of 'missing' parentheses(sp?).


The answer "TRUE" is right.

Simplistically, to me "legal" means "a compilable, runnable program". The
program as is will compile and run. It just won't do what I believed the
person creating the question meant it would do (it prints out the address
of the function instead of invoking it). But there's nothing illegal about
it. It's a question of desired effect. Someone could quite easily want to
do the above in a debugging situation.

So, the program is completely LEGAL (regardless of how many params the
function has). But it *may* also be INCORRECT. But that wasn't the
question...
True. The following is a legal C++ function definition

Void funcTest(int& u, double& v);
{
Cout<<u<<" "<<v<<endl;
}
TRUE


FALSE. The trailing semi-colon on the "funcTest" line results in a syntax
error.


Actually, it is the '{' following the ';' which triggers an error.
Up to the ';' it is a forward declaration.


You are correct. I guess I should have more clearly said "The trailing
semi-colon on the "funcTest" line results in a *subsequent* syntax error."

Since the question stated this was supposed to be a definition (not a
declaration), I assumed the semi-colon was the erroneous part, not the
block following.
True. The word const is used before the array declaration in a function
heading to prevent the function from modifying the array.
What is an 'array declaration' in a 'function heading'?
e.g.

void PrintData(int const data[], int size)
{
for (int i = 0; i < size; ++i)
{
printf("%d\n", data[i]); // OK
data[i] = 0; // BAD. const object
}
}
FALSE
TRUE. (What else would the const do?)


Give a hint to the compiler, that the function won't.
BTW: you can cast the 'const' away ...


Thanks. That was a rhetorical question to the previous caller. ;)

Markus


Dec 13 '05 #15

P: n/a
Richard wrote:
Can any one correct these true and false answer for me? I did not but I
don't know if they are all corrected. THanks


I counted 17 right out of 33 -- did you flip a coin?

Dec 13 '05 #16

P: n/a
Jay Nabonne wrote:

On Mon, 12 Dec 2005 23:28:09 +0100, Markus Becker wrote:
Jay Nabonne <ja*********@sonicNOSPAM.com> schrieb:
> Float test();
> The statement
> Cout<<test;
> Is legal because the function test has no parameters.
FALSE

Perfectly *legal* (mis-casing of "cout" ignored). It prints out the
address of the function test. It will work even if the function has


So the answer 'FALSE' is right, because it is not legal because of
no parameters, but because of 'missing' parentheses(sp?).


The answer "TRUE" is right.

Simplistically, to me "legal" means "a compilable, runnable program". The
program as is will compile and run.


Right.
But the predefined answer also gave a reason why that should be legal.
And that reason is wrong. Thus the answer to the whole question must be:
False.

--
Karl Heinz Buchegger
kb******@gascad.at
Dec 13 '05 #17

P: n/a
On Tue, 13 Dec 2005 10:09:06 +0100, Karl Heinz Buchegger wrote:
Jay Nabonne wrote:

On Mon, 12 Dec 2005 23:28:09 +0100, Markus Becker wrote:
> Jay Nabonne <ja*********@sonicNOSPAM.com> schrieb:
>
>>>> Float test();
>>>> The statement
>>>> Cout<<test;
>>>> Is legal because the function test has no parameters.
>>> FALSE
>>
>> Perfectly *legal* (mis-casing of "cout" ignored). It prints out the
>> address of the function test. It will work even if the function has
>
> So the answer 'FALSE' is right, because it is not legal because of
> no parameters, but because of 'missing' parentheses(sp?).
>


The answer "TRUE" is right.

Simplistically, to me "legal" means "a compilable, runnable program". The
program as is will compile and run.


Right.
But the predefined answer also gave a reason why that should be legal.
And that reason is wrong. Thus the answer to the whole question must be:
False.


Given that, I agree.

As an aside, somehow I doubt the person giving these questions thought
about it to this extent. I hope it wasn't a teacher that came up with
the above "problem".

- Jay
Dec 13 '05 #18

P: n/a
Jay Nabonne wrote:

Right.
But the predefined answer also gave a reason why that should be legal.
And that reason is wrong. Thus the answer to the whole question must be:
False.


Given that, I agree.

As an aside, somehow I doubt the person giving these questions thought
about it to this extent. I hope it wasn't a teacher that came up with
the above "problem".


I bet it was a teacher :-)

--
Karl Heinz Buchegger
kb******@gascad.at
Dec 13 '05 #19

P: n/a

On 12/12/05 5:04 PM, in article
pa****************************@sonicNOSPAM.com, "Jay Nabonne"
<ja*********@sonicNOSPAM.com> wrote:
On Mon, 12 Dec 2005 23:28:09 +0100, Markus Becker wrote:
Jay Nabonne <ja*********@sonicNOSPAM.com> schrieb:
> Float test();
> The statement
> Cout<<test;
> Is legal because the function test has no parameters.
FALSE

Perfectly *legal* (mis-casing of "cout" ignored). It prints out the
address of the function test. It will work even if the function has


So the answer 'FALSE' is right, because it is not legal because of
no parameters, but because of 'missing' parentheses(sp?).


The answer "TRUE" is right.

Simplistically, to me "legal" means "a compilable, runnable program". The
program as is will compile and run. It just won't do what I believed the
person creating the question meant it would do (it prints out the address
of the function instead of invoking it). But there's nothing illegal about
it. It's a question of desired effect. Someone could quite easily want to
do the above in a debugging situation.

So, the program is completely LEGAL (regardless of how many params the
function has). But it *may* also be INCORRECT. But that wasn't the
question...


The answer to the question being asked is "FALSE".

We know that the code is legal, the question tells us that "cout<<test" is
legal.

We are to decide whether the reason that the code is legal is due to the
fact that test() takes no parameters. Since the code would still be legal if
test did take one or more parameters, the number of parameters that test()
accepts could not be the explanation for why the the code compiles. So the
answer is "FALSE".

The actual reason the code is legal is for the reasons already provided
above.

Greg

Dec 13 '05 #20

P: n/a
On Tue, 13 Dec 2005 16:27:29 +0000, Greg Herlihy wrote:

The answer to the question being asked is "FALSE".

We know that the code is legal, the question tells us that "cout<<test" is
legal.

We are to decide whether the reason that the code is legal is due to the
fact that test() takes no parameters. Since the code would still be legal if
test did take one or more parameters, the number of parameters that test()
accepts could not be the explanation for why the the code compiles. So the
answer is "FALSE".

The actual reason the code is legal is for the reasons already provided
above.

Greg


Makes perfect sense. Thanks.

Dec 13 '05 #21

P: n/a
Jay Nabonne <ja*********@sonicNOSPAM.com> schrieb:
Simplistically, to me "legal" means "a compilable, runnable program". The
program as is will compile and run. It just won't do what I believed the
person creating the question meant it would do (it prints out the address
That's the problem with programs: They don't do what the programmer
_wanted_ it to do, but it will do what the programmer _told_ it to ;-)
of the function instead of invoking it). But there's nothing illegal about
it. It's a question of desired effect. Someone could quite easily want to
do the above in a debugging situation.
The question had some hint on _why_ the answer should be FALSE or TRUE
and this has nothing to do with the number of arguments.
You are correct. I guess I should have more clearly said "The trailing
semi-colon on the "funcTest" line results in a *subsequent* syntax error."

Since the question stated this was supposed to be a definition (not a
declaration), I assumed the semi-colon was the erroneous part, not the
block following.


Semantically, it is, but syntactically it is not. We should try to be
exact-to-the-word in this group, shouldn't we?
TRUE. (What else would the const do?)


Give a hint to the compiler, that the function won't.
BTW: you can cast the 'const' away ...


Thanks. That was a rhetorical question to the previous caller. ;)


*g*

I didn't mean to criticize you, it was meant to make the topic a little
bit clearer to the previous poster just in case he didn't get your
rhetoric. :-)

Markus
Dec 31 '05 #22

P: n/a
Jay Nabonne <ja*********@sonicNOSPAM.com> schrieb:
Makes perfect sense. Thanks.


It could be that you did not get my unquoted point because
of the fact that english isn't my native language and at times
my command of it is a little bit shakey.
Especially when it comes to nit-picking. ;-)

Markus
Dec 31 '05 #23

This discussion thread is closed

Replies have been disabled for this discussion.