Concept explainers
(Integer Equivalent of a Character) Here is a peek ahead. In this chapter you learned about integers and the type int. C++ can also represent uppercase letters, lowercase letters and a considerable variety of special symbols. C++ uses small integers internally to represent each different character. The set of characters a computer uses and the corresponding integer representations for those characters are called that computer’s characterset You can print a character by enclosing that character in single quotes, as with
cout «; // print an uppercase A
You can print the integer equivalent of a character using static_cast as follows:
cout « static cast<int>(‘A); // print>’A’as an integer
This is called a castoperation (we formally introduce casts in Chapter 4). When the preceding statementexecutes, it prints the value 65 (on systems that use the ASCII character set). Write a programthat prints the integer equivalent of a character typed at the keyboard. Store the input in a variable oftype char.Test your
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
C++ How To Program (Early Objects Version), Global Edition, With Access Card, 10 Ed
Additional Engineering Textbook Solutions
Starting Out with Python (4th Edition)
Starting out with Visual C# (4th Edition)
Starting Out With Visual C# (5th Edition)
Starting Out with Java: Early Objects (6th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Data Structures and Algorithms in Java
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr