Programming Fundamentals/Character Data Type

From Wikibooks, open books for an open world
Jump to navigation Jump to search

An introduction to the character data type.

Overview of the Character Data Type[edit | edit source]

The character data type basically represents individual or single characters. Characters comprise a variety of symbols such as the alphabet (both upper and lower case) the numeral digits (0 to 9), punctuation, etc. All computers store character data in a one byte field as an integer value. Because a byte consists of 8 bits, this one byte field has 28 or 256 possibilities using the positive values of 0 to 255.

Most microcomputers use the ASCII (stands for American Standard Code for Information Interchange and is pronounced "ask-key") Character Set which has established values for 0 to 127. For the values of 128 to 255 they usually use the Extended ASCII Character Set. When we hit the capital A on the keyboard, the keyboard sends a byte with the bit pattern equal to an integer 65. When the byte is sent from the memory to the monitor, the monitor converts the integer value of 65 to into the symbol of the capital A to display on the monitor.

The character data type attributes include:

C++ Reserved Word char
Represent Single characters
Size 1 byte
Normal Signage Unsigned (positive values only)
Domain (Values Allowed) Values from 0 to 127 as shown in the standard ASCII Character Set, plus values 128 to 255 from the Extended ASCII Character Set
C++ syntax rule Single quote marks – Example: 'A'

Demonstration Program in C++[edit | edit source]

Creating a Folder or Sub-Folder for Source Code Files[edit | edit source]

Depending on your compiler/IDE, you should decide where to download and store source code files for processing. Prudence dictates that you create these folders as needed prior to downloading source code files. A suggested sub-folder for the Bloodshed Dev-C++ 5 compiler/IDE might be named:

  • Demo_Programs

If you have not done so, please create the folder(s) and/or sub-folder(s) as appropriate.

Download the Demo Program[edit | edit source]

Download and store the following file(s) to your storage device in the appropriate folder(s). Following the methods of your compiler/IDE, compile and run the program(s). Study the soruce code file(s) in conjunction with other learning materials.

Download from Connexions: Demo_Character_Data_Type.cpp

Definitions[edit | edit source]

A data type representing single text characters like the alphabet, numeral digits, punctuation, etc.
American Standard Code for Information Interchange
single quote marks
Used to create character type data within the C++ programming language.