going to use in our program.
13. What are the three purposes for a variable declaration?
The type of the variable ( int ), the name of the variable ( total_count ), and a commen t
describing the variable.
14. The FORTRAN language (among others) would automatically declare a variable the first time it
was used. Variables that began with A-H,O-Z where automatically declared float and variables
that begin with I-M were automatically declared int. Discuss the advantages and disadvantages of
this “feature.” (Note: FORTRAN was invented before lowercase was widely used in computes,
so all variables were written in uppercase only.)
Advantages
You don’t have to declare variables .
Disadvantages
You got names like KOUNT to force the count variable to be an integer type.
Misspelling of variable names could not be caught by the compiler.
Note: When I was writing FORTRAN programs I wanted to force the compiler to require
that all variable names be declared. I did this by the statement:
IMPLICIT COMPLEX (A-Z)
This told the compiler that any variable that was not declared was to be considered a
complex variable. Because complex variables required a special syntax and because I
didn’t use them, any misspelled variable name showed up as a compiler error:
Misuse of a complex variable.
15. Define std::cout and use it in a C++ statement.
std::cout is the C++ class that is used for writing data to the screen. Example :
std::cout << "Hello World
";
16. Define “assignment statement” and give an example.
Assignment statements take expressions and put them in variables. Example:
result = 45 / 36;
17. What is the difference between a real and an integer variable?
Integer variables can only hold whole number or integers such as 1, 5, 98, and -42. Real
or floating point variables can hold fractional numbers such as 5.3, 8.6, and 45.2. Note:
Any number with a decimal point is floating point, even if it looks like 5.0.
18. Give an example of an integer division statement and a floating point division statement?
i_var = 12 / 5; // Integer Division
Page 12
f_var = 12.0 / 5.0; // Floating point division
19. The same operator ‘/’ is used for both floating point and integer divides. How does the compiler
know which one to use?
The compiler checks both sides of the division to see if either the divisor or the dividend
is a floating point number. If either one is floating point, then a floating point divide is
Practical C++ Programming by manish baranwal
Start from the beginning
