Lect 6
Lect 6
Data Types
• unsigned integer
• signed integer
• unsigned short
• signed short
• unsigned long
• signed long
Countable Data Types 27
Countable Data Types 28
Countable Data Types 29
Important Take Away 30
Measurable Data Types 31
• float
• double
• long double
Measurable Data Types 32
Measurable Data Types 33
34
Boolean Data Type 35
Datatype
Range of character is -128 to 127
Range of unsigned character is 255
CHAR_MIN
CHAR_MAX
UCHAR_MAX
38
39
#include <iostream>
Character
Datatype
int main ()
{
cout << CHAR_MIN <<endl ;
cout << CHAR_MAX <<endl ;
cout <<UCHAR_MAX <<endl ;
char sub1_grade = 'A’ , sub2_grade = ‘B+’ ;
cout << sub1_grade <<endl <<sub2_grade <<endl ;
return 0 ;
}
40
#include <iostream>
Character
Datatype
int main ()
{
char c = 65 ;
cout <<c <<endl ;
c = ‘65’ ;
cout << c <<endl ;
c = 200 ;
cout << c <<endl ;
return 0 ;
}
Store sequence of characters
In coding we use char [] or string for string
datatype
The value must be enclosed in double quotes (“ “)
Syntax: char variable_name [size in number] =
“Value” ;
String
Example: char std_name = “Ahmad” ;
string variable_name = “value” ;
Datatype string std_name = “Mujtaba” ;
Char [n] datatype will take n number of bytes of
memory.
String datatype will take n number of bytes of
memory where n represents the number of
characters in string.
41
What will be the output of following program?
#include <iostream>
using namespace std ;
int main ()
String {
char name [10] = "Mujtaba" ;
Datatype string name1 = "Mujtaba" ;
cout << name << “\t” << sizeof (name) <<endl;
cout << name1 << “\t” << sizeof (name1) <<endl;
return 0 ;
42
43