
Data Types February 7, 2006
1
Data Types
Data Types –
–Declarations
Declarations
and Initializations
and Initializations
Larry Caretto
Computer Science 106
Computing in Engineering
and Science
February 7, 2005
2
Outline
• Review last week
• Meaning of data types
• Integer data types have no decimal
point and integer division truncates
• Floating point data types: approximate
representation of decimal numbers
• Character, string and boolean (logical)
data types
3
Review of Last Week
• Basic elements of C++ programs
– Template #include, using namespace std;
int main(), return EXIT_SUCCESS;
– C++ is case sensitive
– White space does not matter except in
string constants
– End statements with a semicolon (;)
– Braces { and } frame logical code blocks
– Will use in lab this week
4
Review of Last Week II
• Screen output using cout and <<
• Keyboard input using cin and >>
• Variables refer to memory locations
– Use letters, numbers and _
– Start with letter or _
– 31 characters maximum
– Use meaningful names
– Variables are case sensitive (x2 is not X2)
5
Review Variables and Memory
• Program variables refer to computer
memory (RAM) locations
• When we use a variable (say x) we get
the value in the memory location the
compiler associated with this variable
– x = 3; // assigns the value 3 to x
– cout << x; // writes value of x to the screen
– y = x; // assigns value of x to y
– x = x + 3; // replaces x by x + 3
6
Computer Memory
• Cells show memory address, associated
variable name and value stored (if any)
• What is effect of y2 = PI * rad * rad?
– What happens to cell 106? to cells 102 and 104?
– Cell 106 gets the new value of π(3.5)2
– Cells 102 and 104 are not changed
107 _data
13
106 y2105 nam
“CSUN”
104 rad
3.5
103 i
0
102 PI
3.1415926
101 x1
15
100 Var
12.2
Address
Variable
name
Value