Basic Elements of C++ Programming Language Identifiers C/C++ is case-sensitive: Sum, sum, and SUM are distinct identifiers. By convention, if an identifier consists of two or more words you may do one of the following: Separate the words with the underscore characters. Examples:
interest_rate
sum_of_dice
Concatenate all the words and capitalize the first character of each word except the first. Examples:
interestRate
sumOfDice
Keywords Examples of keywords are: auto, do, while, int, float, long, and const. You are not allowed to use keywords as your own identifiers Standard identifiers Examples: scanf and printf You may use a standard identifier as an identifier only if you do not want to use the object that comes with the compiler.
© Gilbert Ndjatou
Page 1
Variables and Basic Data Types A variable has: o A name, o A data type o And an address.
Data Type
Type of Data
Range of Values
bool
Boolean value
true, false
char
A single character
ASCII character representations
short short int unsigned short unsigned short int int unsigned unsigned int long long int unsigned long unsigned long int float double long double
15
15
Size on PC
1 byte
integers
-2 (-32,768) to 2 – 1 (32,767)
2 bytes
integers
0 to 216 – 1 (65,535)
2 bytes
integers
-231 (-2,147,483,648) to 231 – 1 (2,147,483,647)
4 bytes
32
integers
0 to 2 – 1 (4,294,967,295)
4 bytes
integers
-231 (-2,147,483,648) to 231 – 1 (2,147,483,647)
4 bytes
integers
0 to 232 – 1 (4,294,967,295)
4 bytes
Floating point decimals Floating point decimals Floating point decimals
Negative range: -3.4028235E+38 to -1.4E-45 Positive range: 1.4E-45 to 3.4028235E+38 Negative range: -1.7976931348623157E+308 to -4.9E-324 Positive range: 4.9E-324 to 1.7976931348623157E+308 Negative range: -1.18E+4932 to -3.37E-4932 Positive range: 3.37E-4932 to 1.18E+4932
4 bytes 8 bytes 10 bytes
The number of bytes that are used to represent a data type depends on the computer. You can use the sizeof() function to find out the size of a basic data type on a computer. The following statement displays the size of int, long, and double data types: cout