Download presentation
Presentation is loading. Please wait.
Published byChester Heath Modified over 8 years ago
1
Lecture 4 Monday Sept 9, 2002
2
Variables and Data Types ►A►A►A►A variable is simply a name given by the programmer that is used to refer to computer storage location (memory). ►T►T►T►The term variable is used because the value stored in the variable can change. ► T► T► T► The value stored is the data. ►D►D►D►Data can be of different types.
3
Pictorial understanding Variables 451257 ab c 165225484527 a b c are variables. 1652 2548 4527 are memory addresses. 45 12 57 are values stored or data.
4
Rules for Variable names & declaration ► T► T► T► The variable name must begin with a letter or underscore(_), and may contain only letters, underscores, or digits. It cannot contain any blanks, commas, or special symbols, such as () &, $ # etc… ► A► A► A► A varible name cannot be a keyword ► T► T► T► The variable name cannot consist of more than 31 characters.
5
Keywords ► A► A► A► A keyword is a word that is set aside by the language for a special purpose and can only be used in a specific manner. Eg : auto voidshort sizeof break switch privatefloat continueforifdelete etc……
6
Types of Data Data Types Integer Short intLong int Unsigned short int Unsigned long int Floatdouble Long double char Signed chatUnsigned char
7
Definitions ► I► I► I► Integer – A zero, or any positive or negative value without a decimal point. eg : 0, 5, -19, -26351 ► F► F► F► Float – Also called real number, any positive or negative number having a decimal point eg : 10.652, -6.3, 0.34, -6.67
8
Definitions contd… ►C►C►C►Char – Includes : 1. l etters of the alphabet (upper and lower case). 2. T en digits 0 thro 9. 3. S pecial symbols – $, !, b, A etc…. 4. A single character is any one letter, digit or special symbol enclosed within single quotes. Eg ‘ A ‘ ‘ $ ‘ ‘ b’
9
Char contd….. ►C►C►C►Characters are stored as ASCII or EBCDIC code. ►A►A►A►ASCII – American standard code for Information Interchange. ►E►E►E►EBCDIC – Extended Binary Coded Decimal Interchange Code. ►E►E►E►Each code corresponds to a number between -128 to 128 if signed else 0 to 255 for unsigned.
10
Definitions contd… ► s► s► s► short int – represents fairly small integer values and requires half the amount of storage with respect to int. ► l► l► l► long int represents fairly large integer values and requires double the amount of storage with respect to int. ►U►U►U►Unsigned is used to increase the range in the positive side.
11
► d► d► d► double - - - - refers to same data type as float but with greater size and range of numbers. ► l► l► l► long double - To further increase size and range of numbers. ►N►N►N►Note: In some computers int and short int have the same storage size.
12
Tabular understanding ► Primary Data types Data Type Data TypeSize ( bytes) Range CharIntFloatdouble1248 -128 to 127 -32768 : 32767 -3.4e38 : 3.4e38 -1.7e308: 1.7e308
13
Integer data types Data type Size (bytes) Range - Short Int or signed short int int - Unsigned short int - Int or signed int - unsigned int - Long int or signed long int int - Unsigned long int 222244-32768:32767 0 : 65,535 -32768 : 32767 0 : 65535 -2147483648:2147483647 0 :4294967295
14
Floating point data types Data type Size ( bytes ) Range floatdouble Long double 4810 -3.4e38 : 3.4e38 -1.7e308 : 1.7e308 -1.7e308 : 1.7e308 -1.7e4932 : 1.7e4932
15
Character data types Data type Size ( bytes ) Range Char or signed char Unsigned char 11 -128 : 127 0 : 255
16
sizeof operator ► D► D► D► Different machines give different storage size for the data types. ►T►T►T►The previously quoted sizes and range are for the MS-DOS environment. ►T►T►T►The sizeof operator is used to find the storage size of data types of the computer under use. ►T►T►T►The info got from this operator can be very useful when transferring a program to a different computer.
17
sizeof operator contd ► Usage ExpressionResult sizeof(char)sizeof(int)sizeof(float)sizeof(double)1248
18
Problem # 3 ► T► T► T► To find storage size of a data type ? #include<iostream.h> // preprocessor directive void main() // function main { int a =3, ss; // Variable declaration part ss=sizeof(a); // find size of int a cout<<“The size of int a is ”<<ss<<endl; cout<<“the value of a is ”<<a<<endl; }
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.