lecture17 - Monday, December 6 th Fill out class evaluation...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Monday, December 6 th Fill out class evaluation forms Ice cream (mmmmmm, Ice Cream) Finish Operator Overloading Start Review: ASCII Pointers Classes Constructors and Destructors The final exam is this FILL IN THE BLANK. Review session on FILL IN THE BLANK! Characters and ASCII Every symbol on the keyboard: letter , digit , period , space , etc. is represented by a numeric value in memory ! A = 65, B = 66, ..., Z = 90 a = 97, b = 98, ..., z = 122 = 32 (space), ! = 33, , = 44, etc... 0 = 48, 1 = 49, 2 = 50,... 9 = 57 main() { char c1 = C ; // note: c NOT C char c2 = 67 ; cout << c1 << endl; cout << c2 << endl; } Characters and ASCII c1 67 When using char variables in C++, you may use symbolic characters or ASCII (numeric) values. c2 67 C C A = 65 B = 66 C = 67 ... Z = 90 When you use cout to print a char variable , cout converts the number back to a symbol for display on the screen. Characters and ASCII void main(void) { char ch; cout >> Enter a char: ; cin >> ch; cout << ch << endl; cout<< static_cast<int>( ch ) << endl; ++ch; // treat it just like a number! cout << ch << endl; cout<< static_cast<int>( ch ) << endl; } Enter a char: d ch 100 d 100 You can print out the ASCII value of a char variable instead of printing its symbol using a static_cast . 101 e 101 Whats the Difference? void main(void) { int i cout >> Enter an int: ; cin >> i; cout << i << endl; char c; cout >> Enter a char: ; cin >> c; cout << static_cast<int>(c) << endl; cout << c; } If you use cin with an int variable , C++ converts the symbol you type into its integer equivalent. i c Enter an int: 9 9 9 Enter a char: 9 57 If you use cin with a char variable , it converts the symbol you type into its ASCII value, not its integer value. 57 9 num2 Characters and ASCII void main(void) { char c; cout<<"Enter uppercase letter: "; cin >> c; int num = c - 65; cout << c << " is letter # " << num; cout << endl; int num2 = c - 'A'; cout << c << " is letter # " << num2; cout << endl; if ('A' == 65) cout << "A is 65!\n"; if ('0' == 48) cout << "0 is 48!\n"; } c num Enter uppercase letter: F 70 5 F is letter 5 num2 = c - 65; F is letter 5 5 A is 65 0 is 48 main() { int a=1, b=2; int *p1, *p2; // how to define 2 ptrs p1 = &a; p2 = &b; // whats the diff between if (*p1 == *p2) { do something; }// and if (p1 == p2) { do something; } } 00000000 00000001 00006420 00006421 00006422 00006423 00006424 00006425 00006426 00006427 00006428 00006429 00006430 00006431 00006432 00006433 00006434 00006435 a 1 b 2 p1 p2 6420 6424 *p1 == *p2 and p1 == p2 *p1 == *p2...
View Full Document

Page1 / 40

lecture17 - Monday, December 6 th Fill out class evaluation...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online