Correcting answers

R

Richard

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

Victor Bazarov

Richard said:
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
 
H

Howard

Richard said:
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
 
H

Howard

Howard said:
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
 
E

Earl Purple

Richard said:
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'.
 
V

Victor Bazarov

Earl said:
<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
 
D

dave

Richard said:
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
 
V

Victor Bazarov

Jay said:
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
 
J

Jay Nabonne


Usually. But:

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

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

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

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

Same as before - unless it's const.

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

FALSE.

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

TRUE. (What else would the const do?)

TRUE.

struct Point { int x, y; }

void myFunc(Point inp, Point& outp);


- Jay
 
J

Jay Nabonne

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!
 
I

int2str

Richard said:
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
 
M

Markus Becker

Jay Nabonne said:
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?).
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.

What is an 'array declaration' in a 'function heading'?
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
 
J

Jay Nabonne

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...
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.
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); // OK
data = 0; // BAD. const object
}
}
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. ;)
 
O

Old Wolf

Richard said:
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?
 
K

Karl Heinz Buchegger

Jay said:
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.
 
J

Jay Nabonne

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
 
K

Karl Heinz Buchegger

Jay said:
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 :)
 
G

Greg Herlihy

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
 

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,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top