Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data in a C++ Program Numeric data and character data

Similar presentations


Presentation on theme: "Data in a C++ Program Numeric data and character data"— Presentation transcript:

1 Data in a C++ Program Numeric data and character data Use variables to hold a data in memory Each variable has a name Each variable has a type Each variable holds a value that you stored in it Valid variable names: salary, aug99_sales, I, AgeLimit, Amount Never give a variable name the same name as a C++ command Give your variables meaningful names

2 signed char (same as char) int unsigned int signed int (same as int)
Variable Types char unsigned char signed char (same as char) int unsigned int signed int (same as int) short int unsigned short int long int long (same as long int) signed long int (same as long) unsigned long int float double long double Define Variables main() { int age, weight; char initial; float salary; // Rest of program follows }

3 Putting Values in Variables
main() { int age, dependents; float salary; age = 32; salary = ; dependents = 2; // Rest of program follows } { char first, middle, last; first = ‘G’; middle = ‘M’; last = ‘P’;

4 You can use a constant variable anywhere you can use a variable, but
Constant Variables You can use a constant variable anywhere you can use a variable, but you cannot change constant variables after their initializations at definitions const int days_of_week = 7; You must put an initial value into the constant variable C++ assumes a constant without type to be of int type main() { const float salary = ; const int age = 16; // Rest of program follows }


Download ppt "Data in a C++ Program Numeric data and character data"

Similar presentations


Ads by Google