help with assignment please

Hello everyone I am enrolled in a beginners C++ class and have some doubts about some questions in a take home exam, please I need help.

the declaration int a, b, c; is equivalent to which of the following?
a. inta , b, c;
b. int a,b,c;
c. int abc;
d. int a b c;

I think the answer is B but I really don't know why. Also I would really appreciate if you guys could check my answers in the following questions:

-Declare an int variable num and initialize it to 13.
int num = 13;

-declare a char variable grade and set it to the character A.
char grade;

grade = 'A';

-declare in variables to store four integers.
int a, b, c, d;

-Copy the value of an int variable firstNum into and int variable secondNum.
secondNum = firstNum;

Thank you very much guys I really want to do great in this class.

closed account (zb0S216C)
facundokpo24 wrote:
I think the answer is B (sic)

Yes, the answer is B. But the important part is: Why is B the correct answer? Variable declarations such as this require the comma between each symbol to separate them from each other. Without the commas, the compiler will think that each symbol is a separate statement (and would give you an error as a result because of missing semi-colons).

As for your questions, you're correct on all of them. Although, there's an alternative answer to the first question but that is irrelevant to know right now, so I won't burden your mind with it.

I hope you do well :)

Wazzak
Last edited on
Topic archived. No new replies allowed.