View Single Post
Old 04-30-2005, 01:12 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Quote:
1.Do you have to tell what variable it needs to use before it uses one?
Answer: No, if you don't assign C++ the type of variable before its use, it will automaticly be an int.
Not anymore. This rule was dropped with the current ISO C++ (1998, built on C89) standard. The current ISO C (C99) standard dropped this rule as well.

Quote:
17.What statement makes sure that bool variables output “true” and “false”?

Answer: cout.setf(cout.boolalpha);
Unusual. Do one of these:
cout.setf(ios::boolalpha);
cout << boolalpha << mybool;


Quote:
8.What is an expression?

Answer: An expression is a statement involving any sort of mathematical operation, that gives (returns) a value.
No. It *may* return a value. See this from chapter 5 of the C++ standard:

Clause 5 defines the syntax, order of evaluation, and meaning of expressions. An expression is a sequence of operators and operands that specifies a computation. An expression can result in a value and can cause side effects.

Quote:
9.Explain the shown examples in detail...

// example 1
int n1, n2;
n1 = 5;
n2 = ++n1;

// example 2
int n1, n2;
n1 = 5;
n2 = n1++;

Answer: n1++ and ++n1 both add one to their variable. The first example shows n1 initialized as 5, then changed to 6 after n2 was initialized the same as n1 but with autoincrement, changing both values to 6. Example 2 shows n1 initialized to 5, then n2 initialized the same as n1, also incremented but with the ++ unary operators pointed to the right, changing n2 from 5 to 6, but leaving n1 to 5.
For n1 in both cases, we can't say the word "change". The behaviour or unitialized or unassign variables is undefined. In each instance, change the word "initialze(d)" by "assign(ed)". There is a (important) difference between assigning and initializing.

Quote:
20.How many digits after the decimal point does a float go on for? Any exceptions? How about a double var?

Answer: A float var supports about 6 digits after the decimal, but it may go over the limit llike 3.33333347 due to vagaries in floating calculatations.
Close.
The answer is *exactly* 6.
Quote:
A double var has the same exceptions as the float, but supports up to and around 13 digits.
16

Becarefull with these things. The number of digits is implementation defined. So on a 4 bit system, you can forget so many digits.
__________________
Valmont is offline   Reply With Quote