Connecting Tech Pros Worldwide Forums | Help | Site Map

Correcting answers

Richard
Guest
 
Posts: n/a
#1: Dec 12 '05
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.



Victor Bazarov
Guest
 
Posts: n/a
#2: Dec 12 '05

re: Correcting answers


Richard wrote:[color=blue]
> Can any one correct these true and false answer for me? I did not but I[/color]

I don't understand your statement "I did not but I don't know ..."
[color=blue]
> don't know if they are all corrected. THanks
> [...][/color]

And, no, we don't do homeworks.

V
Howard
Guest
 
Posts: n/a
#3: Dec 12 '05

re: Correcting answers



"Richard" <nomail1235@yahoo.com> wrote in message
news:jaqdnZWMUIrODgDenZ2dnUVZ_sCdnZ2d@comcast.com. ..[color=blue]
> 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.
>
>[/color]

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


Howard
Guest
 
Posts: n/a
#4: Dec 12 '05

re: Correcting answers



"Howard" <alicebt@hotmail.com> wrote in message
news:eTgnf.270973$zb5.85632@bgtnsc04-news.ops.worldnet.att.net...[color=blue]
>
> "Richard" <nomail1235@yahoo.com> wrote in message
> news:jaqdnZWMUIrODgDenZ2dnUVZ_sCdnZ2d@comcast.com. ..[color=green]
>> 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.
>>
>>[/color]
>
> 1) How coud we possibly know if the answers are correct, when you haven't
> given the questions???
>[/color]

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



Earl Purple
Guest
 
Posts: n/a
#5: Dec 12 '05

re: Correcting answers



Richard wrote:[color=blue]
> 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[/color]

<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'.

Victor Bazarov
Guest
 
Posts: n/a
#6: Dec 12 '05

re: Correcting answers


Earl Purple wrote:[color=blue]
> Richard wrote:
>[color=green]
>>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[/color]
>
>
> <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'.
>[/color]

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

V
W Marsh
Guest
 
Posts: n/a
#7: Dec 12 '05

re: Correcting answers


On Mon, 12 Dec 2005 12:46:10 -0500, Victor Bazarov
<v.Abazarov@comAcast.net> wrote:
[color=blue]
>Earl Purple wrote:[color=green]
>> Richard wrote:
>>[color=darkred]
>>>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[/color]
>>
>>
>> <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'.
>>[/color]
>
>Actually it must use *two* lower-case 'r's.
>
>V[/color]

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

retuRn someValue;
}

DOH!
dave
Guest
 
Posts: n/a
#8: Dec 12 '05

re: Correcting answers



"Richard" <nomail1235@yahoo.com> wrote in message
news:jaqdnZWMUIrODgDenZ2dnUVZ_sCdnZ2d@comcast.com. ..[color=blue]
> 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.[/color]

FALSE[color=blue]
>
>
> False. An indentifier can be any sequence of digits, leters, and the
> underscore.[/color]

FALSE
[color=blue]
>
>
>
> True. When trying to store a double value in an int variable, the double
> value is rounded to the nearest interger.
>[/color]
TRUE[color=blue]
>
>
> False. An if statement cannot be nested in a switch statement, but a[/color]
switch[color=blue]
> statement can be nested in an if statement.[/color]

FALSE[color=blue]
>
>
>
> True. The execution of a break statement in a while loop terminates the
> loop.
>[/color]
TRUE[color=blue]
>
>
> True. A function definition consists of the function heading and the body[/color]
of[color=blue]
> the function.
>[/color]
TRUE[color=blue]
>
>
> True. Parameters allow the programmer to use different values each time[/color]
the[color=blue]
> functions is called.
>[/color]
TRUE[color=blue]
>
>
> False. The execution of the return statement in a user-defined function
> terminates the program.
>[/color]
FALSE[color=blue]
>
>
> True. It is not necessary to specify the names of formal parameters in a
> function prototype.
>[/color]
TRUE[color=blue]
>
>
> False. The return statement
>[/color]
[color=blue]
>
>
> Return x +1;
>
> First returns the values of x and then increments the values[/color]
of[color=blue]
> x.
>[/color]
FALSE[color=blue]
>
>
> True. The following return statement return the value 10.
>
> Return 10,16;
>[/color]

FALSE[color=blue]
>
>
> 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;
>
>[/color]
FALSE[color=blue]
>
> True. Given the function prototype
>
>
>
> Float test();
>
> The statement
>
> Cout<<test;
>
> Is legal because the function test has no parameters.[/color]
FALSE[color=blue]
>
>
>
> True. Given the function prototype
>
> Double testAlpha (int u, char v, double t);
>
> The following statement is legal.
>
> Cout<<testAlpha(5, 'A', 2);
>[/color]
TRUE[color=blue]
>
>
> False. If a formal parameters is a value parameter and the corresponding
> actual parameters is a variable, the actual parameter can be modified.
>[/color]
FALSE[color=blue]
>
>
> False. If an ampersand, & is attached to the data type of a formal
> parameter, the corresponding actual parameter must be a variable.
>[/color]
TRUE[color=blue]
>
>
> True. A value parameter only changes its own content without changing the
> value of the actual parameter.
>[/color]
TRUE[color=blue]
>
>
> True. A variable name can be passed to a value parameter.
>[/color]
TRUE[color=blue]
>
>
> False. The corresponding actual parameter for a reference parameter can be
> any expression
>[/color]
FALSE[color=blue]
>
>
> True. Any parameter the receives a value and also sends a value outside[/color]
the[color=blue]
> function must be declared as reference parameter.
>[/color]
FALSE[color=blue]
>
>
> True. If a formal parameter is a reference parameter, the corresponding
> actual parameter must be a varialble
>[/color]

TRUE[color=blue]
>
>
> True. The pass by value mechanism must be used if the calling code is to
> receive values back from the function.
>[/color]
FALSE[color=blue]
>
>
> True. A variable declared outside of every block is called a global
> variable.
>[/color]
TRUE[color=blue]
>
>
> True. In a program global constants have no side effects.
>[/color]
FALSE[color=blue]
>
>
> 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
>[/color]
FALSE[color=blue]
>
>
> True. In C++, function definitions cannot be nested, that is, the[/color]
definition[color=blue]
> of one function cannot be enclosed in the body of another function.
>[/color]
TRUE[color=blue]
>
>
> True. A static variable works the same way as global variable because[/color]
memory[color=blue]
> for the static variables remains allocated during program execution.
>
>[/color]
FALSE[color=blue]
>
> True. The following is a legal C++ function definition
>
> Void funcTest(int& u, double& v);
>
> {
>
> Cout<<u<<" "<<v<<endl;
>
> }[/color]
TRUE[color=blue]
>
> 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
>[/color]
FALSE[color=blue]
>
>
> True. In C++ , when declaring an array as a formal parameter, the size of
> the array must be specified within square brackets.
>[/color]
TRUE[color=blue]
>
>
> True. The word const is used before the array declaration in a function
> heading to prevent the function from modifying the array.
>[/color]
FALSE[color=blue]
>
>
> False. A struct can be passed as a parameter to a function by value or by
> reference.
>[/color]
FALSE[color=blue]
>
>
> True. A function cannot return a value of a type struct
>[/color]
FALSE[color=blue]
>
>
> True. The Address operator is a urary operator that returns the address of
> its operand.
>[/color]
TRUE[color=blue]
>
>
> True. Any number can be directly assigned to a pointer variable.
>[/color]
FALSE[color=blue]
>[/color]


Jay Nabonne
Guest
 
Posts: n/a
#9: Dec 12 '05

re: Correcting answers


On Mon, 12 Dec 2005 12:52:07 -0500, dave wrote:
[color=blue][color=green]
>> True. When trying to store a double value in an int variable, the double
>> value is rounded to the nearest interger.
>>[/color]
> TRUE[/color]

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

- Jay
Jay Nabonne
Guest
 
Posts: n/a
#10: Dec 12 '05

re: Correcting answers


On Mon, 12 Dec 2005 12:52:07 -0500, dave wrote:
[color=blue]
>
> "Richard" <nomail1235@yahoo.com> wrote in message
> news:jaqdnZWMUIrODgDenZ2dnUVZ_sCdnZ2d@comcast.com. ..[color=green]
>>
>>
>> True. The execution of a break statement in a while loop terminates the
>> loop.
>>[/color]
> TRUE[/color]

Usually. But:

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

Is the break statement considered "in the while loop"?
[color=blue][color=green]
>>
>> True. Given the function prototype
>>
>>
>>
>> Float test();
>>
>> The statement
>>
>> Cout<<test;
>>
>> Is legal because the function test has no parameters.[/color]
> FALSE[/color]

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.)
[color=blue][color=green]
>>
>>
>> False. If an ampersand, & is attached to the data type of a formal
>> parameter, the corresponding actual parameter must be a variable.
>>[/color]
> TRUE[/color]

Unless it's const (e.g. "const int &"), in which case it can be bound to a
temporary.
[color=blue][color=green]
>>
>>
>> True. If a formal parameter is a reference parameter, the corresponding
>> actual parameter must be a varialble
>>[/color]
>
> TRUE[/color]

Same as before - unless it's const.
[color=blue][color=green]
>>
>> True. The following is a legal C++ function definition
>>
>> Void funcTest(int& u, double& v);
>>
>> {
>>
>> Cout<<u<<" "<<v<<endl;
>>
>> }[/color]
> TRUE[/color]

FALSE. The trailing semi-colon on the "funcTest" line results in a syntax
error.
[color=blue][color=green]
>>
>>
>> True. In C++ , when declaring an array as a formal parameter, the size of
>> the array must be specified within square brackets.
>>[/color]
> TRUE[/color]

FALSE.

int main(int argc, char* argv[])
{
}
[color=blue][color=green]
>>
>>
>> True. The word const is used before the array declaration in a function
>> heading to prevent the function from modifying the array.
>>[/color]
> FALSE[/color]

TRUE. (What else would the const do?)
[color=blue][color=green]
>>
>>
>> False. A struct can be passed as a parameter to a function by value or by
>> reference.
>>[/color]
> FALSE[/color]

TRUE.

struct Point { int x, y; }

void myFunc(Point inp, Point& outp);


- Jay


Victor Bazarov
Guest
 
Posts: n/a
#11: Dec 12 '05

re: Correcting answers


Jay Nabonne wrote:[color=blue]
> On Mon, 12 Dec 2005 12:52:07 -0500, dave wrote:
>
>[color=green][color=darkred]
>>>True. When trying to store a double value in an int variable, the double
>>>value is rounded to the nearest interger.
>>>[/color]
>>
>>TRUE[/color]
>
>
> AFAIK, it rounds towards zero (truncates). So, FALSE.[/color]

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
Jay Nabonne
Guest
 
Posts: n/a
#12: Dec 12 '05

re: Correcting answers


On Mon, 12 Dec 2005 13:44:36 -0500, Victor Bazarov wrote:
[color=blue]
> Jay Nabonne wrote:[color=green]
>> On Mon, 12 Dec 2005 12:52:07 -0500, dave wrote:
>>
>>[color=darkred]
>>>>True. When trying to store a double value in an int variable, the double
>>>>value is rounded to the nearest interger.
>>>>
>>>
>>>TRUE[/color]
>>
>>
>> AFAIK, it rounds towards zero (truncates). So, FALSE.[/color]
>
> 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.
>[/color]

That's good to know. Thanks!


int2str@gmail.com
Guest
 
Posts: n/a
#13: Dec 12 '05

re: Correcting answers



Richard wrote:[color=blue]
> True. The following return statement return the value 10.
>
> Return 10,16;[/color]

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

Markus Becker
Guest
 
Posts: n/a
#14: Dec 12 '05

re: Correcting answers


Jay Nabonne <jay_nabonne@sonicNOSPAM.com> schrieb:
[color=blue][color=green][color=darkred]
>>> Float test();
>>> The statement
>>> Cout<<test;
>>> Is legal because the function test has no parameters.[/color]
>> FALSE[/color]
>
> Perfectly *legal* (mis-casing of "cout" ignored). It prints out the
> address of the function test. It will work even if the function has[/color]

So the answer 'FALSE' is right, because it is not legal because of
no parameters, but because of 'missing' parentheses(sp?).
[color=blue][color=green][color=darkred]
>>> True. The following is a legal C++ function definition
>>>
>>> Void funcTest(int& u, double& v);
>>> {
>>> Cout<<u<<" "<<v<<endl;
>>> }[/color]
>> TRUE[/color]
>
> FALSE. The trailing semi-colon on the "funcTest" line results in a syntax
> error.[/color]

Actually, it is the '{' following the ';' which triggers an error.
Up to the ';' it is a forward declaration.
[color=blue][color=green][color=darkred]
>>> True. The word const is used before the array declaration in a function
>>> heading to prevent the function from modifying the array.[/color][/color][/color]

What is an 'array declaration' in a 'function heading'?
[color=blue][color=green]
>> FALSE[/color]
>
> TRUE. (What else would the const do?)[/color]

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

Markus
Jay Nabonne
Guest
 
Posts: n/a
#15: Dec 13 '05

re: Correcting answers


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

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...
[color=blue][color=green][color=darkred]
>>>> True. The following is a legal C++ function definition
>>>>
>>>> Void funcTest(int& u, double& v);
>>>> {
>>>> Cout<<u<<" "<<v<<endl;
>>>> }
>>> TRUE[/color]
>>
>> FALSE. The trailing semi-colon on the "funcTest" line results in a syntax
>> error.[/color]
>
> Actually, it is the '{' following the ';' which triggers an error.
> Up to the ';' it is a forward declaration.[/color]

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.
[color=blue]
>[color=green][color=darkred]
>>>> True. The word const is used before the array declaration in a function
>>>> heading to prevent the function from modifying the array.[/color][/color]
>
> What is an 'array declaration' in a 'function heading'?[/color]

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
}
}
[color=blue]
>[color=green][color=darkred]
>>> FALSE[/color]
>>
>> TRUE. (What else would the const do?)[/color]
>
> Give a hint to the compiler, that the function won't.
> BTW: you can cast the 'const' away ...[/color]

Thanks. That was a rhetorical question to the previous caller. ;)
[color=blue]
>
> Markus[/color]

Old Wolf
Guest
 
Posts: n/a
#16: Dec 13 '05

re: Correcting answers


Richard wrote:
[color=blue]
> 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[/color]

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

Karl Heinz Buchegger
Guest
 
Posts: n/a
#17: Dec 13 '05

re: Correcting answers


Jay Nabonne wrote:[color=blue]
>
> On Mon, 12 Dec 2005 23:28:09 +0100, Markus Becker wrote:
>[color=green]
> > Jay Nabonne <jay_nabonne@sonicNOSPAM.com> schrieb:
> >[color=darkred]
> >>>> 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[/color]
> >
> > So the answer 'FALSE' is right, because it is not legal because of
> > no parameters, but because of 'missing' parentheses(sp?).
> >[/color]
>
> The answer "TRUE" is right.
>
> Simplistically, to me "legal" means "a compilable, runnable program". The
> program as is will compile and run.[/color]

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
kbuchegg@gascad.at
Jay Nabonne
Guest
 
Posts: n/a
#18: Dec 13 '05

re: Correcting answers


On Tue, 13 Dec 2005 10:09:06 +0100, Karl Heinz Buchegger wrote:
[color=blue]
> Jay Nabonne wrote:[color=green]
>>
>> On Mon, 12 Dec 2005 23:28:09 +0100, Markus Becker wrote:
>>[color=darkred]
>> > Jay Nabonne <jay_nabonne@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?).
>> >[/color]
>>
>> The answer "TRUE" is right.
>>
>> Simplistically, to me "legal" means "a compilable, runnable program". The
>> program as is will compile and run.[/color]
>
> 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.[/color]

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
Karl Heinz Buchegger
Guest
 
Posts: n/a
#19: Dec 13 '05

re: Correcting answers


Jay Nabonne wrote:[color=blue]
>[color=green]
> >
> > 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.[/color]
>
> 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".[/color]

I bet it was a teacher :-)

--
Karl Heinz Buchegger
kbuchegg@gascad.at
Greg Herlihy
Guest
 
Posts: n/a
#20: Dec 13 '05

re: Correcting answers





On 12/12/05 5:04 PM, in article
pan.2005.12.13.01.04.51.297000@sonicNOSPAM.com, "Jay Nabonne"
<jay_nabonne@sonicNOSPAM.com> wrote:
[color=blue]
> On Mon, 12 Dec 2005 23:28:09 +0100, Markus Becker wrote:
>[color=green]
>> Jay Nabonne <jay_nabonne@sonicNOSPAM.com> schrieb:
>>[color=darkred]
>>>>> 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[/color]
>>
>> So the answer 'FALSE' is right, because it is not legal because of
>> no parameters, but because of 'missing' parentheses(sp?).
>>[/color]
>
> 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...[/color]

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

Jay Nabonne
Guest
 
Posts: n/a
#21: Dec 13 '05

re: Correcting answers


On Tue, 13 Dec 2005 16:27:29 +0000, Greg Herlihy wrote:
[color=blue]
>
> 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[/color]

Makes perfect sense. Thanks.

Markus Becker
Guest
 
Posts: n/a
#22: Dec 31 '05

re: Correcting answers


Jay Nabonne <jay_nabonne@sonicNOSPAM.com> schrieb:
[color=blue]
> 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[/color]

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 ;-)
[color=blue]
> 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.[/color]

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.
[color=blue]
> 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.[/color]

Semantically, it is, but syntactically it is not. We should try to be
exact-to-the-word in this group, shouldn't we?
[color=blue][color=green][color=darkred]
>>> TRUE. (What else would the const do?)[/color]
>>
>> Give a hint to the compiler, that the function won't.
>> BTW: you can cast the 'const' away ...[/color]
>
> Thanks. That was a rhetorical question to the previous caller. ;)[/color]

*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
Markus Becker
Guest
 
Posts: n/a
#23: Dec 31 '05

re: Correcting answers


Jay Nabonne <jay_nabonne@sonicNOSPAM.com> schrieb:
[color=blue]
> Makes perfect sense. Thanks.[/color]

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
Closed Thread