Lecture 05
Lecture 05
Lecture 05
Lecture 5
Unit Objectives
• List the various C data types
• Identify what type a constant is
• Know how to write constants in the
appropriate C++ syntax
• Know the C++ operators and their order of
operations
• Write basic output statements of text and
constants using cout
3
functions you plan on using / / Code i s organized into units called functions
– 'using namespace std;' -- Just do it for now! void printName()
{
• main() function }
cout << "Tommy Trojan" << endl;
Review
• Show how "Hi!\n" would be
stored in the memory below
– Use decimal to represent each byte
– Remember how we terminate a
string
0
1
2
3
4
5
6
…
7
7
Constants
• Integer: 496, 10005, -234
• Double: 1 2 . 0 , - 1 6 . , 0 . 2 3 , - 2.5E- 1 , 4e- 2
• Characters (char type): enclosed in single quotes
– Printing characters: ' a ' , ' 5 ' , ' B ' , ' ! '
– Non-printing special characters use "escape" sequence (i.e. preceded by a \ ):
' \ n ' (newline/enter), ' \ t ' (tab) , ' \ \ ' (slash), ' \ ' ' (apostrophe)
• C-Strings
– 0 or more characters between double quotes 0 104 ‘h’
1 105 ‘i’
" h i 1 \ n " , "12345", " b " , " \ t A n s . i s %d" 2 49 ‘1’
– Ends with a ' \ 0 ' =NULL character added as the last 3 10 ‘\n’
4 00 Null
byte/character to allow code to delimit the end of the string 5 17
SOLUTIONS
21