first c++ practice exam questions. Three basic mc questions.

Here are some questions from my practice exam I can't get...

7. Which of the following variable declarations will compile?
a) double FOObar();
b) double myFavoriteNumber66;
c) int 1ForAll;
d) char _my_character;
e) b & d

Answer is e. I get why c can't be right, it starts with a number. But why can't A work?
-------
8. Which of the following are valid function prototypes? Select all choices that apply.
a) const foo(double x);
b) int bar(x, y);
c) int foobar(double x);
d) char fudge(void x);

I know B is wrong. D is wrong because of the void, but why is A wrong? My guess is it has something to do with the const?
----
17. What does the following print?
cout << "\" ; //this is a comment!";
a) \
b) " ;
c) " ; //this is a comment!
d) none of the above

The answer is C, and I am really at a loss for this. Why isn't the // just a comment? My guess is it has something to do with the " and ;. But then, why isn't there a \ in answer?




Thanks for the help!
Last edited on
im a beginner too, so no gurantee :)

@7. my guess is that a) will compile but its not a variable declaration, but a function. i would not have know e is correct tho lol my guess was d.

@8. i guess the same as you, since a function that returns a const is not going in my head for now.

@17. your guess with the third " is correct, the backslash is not printed because it is an escape sequence initiator used for escape sequences. this means if you want a backslash printed you have to type 2.

Last edited on
@Yezman

#17 - The forward slash, \, is part of an escape sequence. Like when you use \n as a newline, \" is to print a quotation mark, so the first quotation mark stars the sentence to print, the \" print a quote, then the rest of the sentence is printed, including the double backward slashes. There is also a \t, for tab and more. Hope this helps.
Last edited on
7. It's just a function prototype.

8. (A) does not a have a return type.

17. "\ is an escape character. See more [http://www.cplusplus.com/doc/tutorial/constants/]
Ah, thanks for the help. I knew about the \t and \n stuff, but wasn't aware there are a few escape characters (I read the link.)

For the const, that makes a lot of sense about not having a return type. I also see what you mean know about how for number 7 A isn't a variable, but a function.

Thanks again. Solved.
Topic archived. No new replies allowed.