0% found this document useful (0 votes)
54 views22 pages

Lecture 6 C++ Datatype

This document contains a lecture on C++ programming fundamentals and data types by Muhammad Hussain. It discusses built-in data types in C++ like int, float, bool, char, and void. It also covers escape sequences, data type sizes, variables, and different types of operators in C++ like arithmetic, relational, logical, and bitwise operators.

Uploaded by

Ali haider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views22 pages

Lecture 6 C++ Datatype

This document contains a lecture on C++ programming fundamentals and data types by Muhammad Hussain. It discusses built-in data types in C++ like int, float, bool, char, and void. It also covers escape sequences, data type sizes, variables, and different types of operators in C++ like arithmetic, relational, logical, and bitwise operators.

Uploaded by

Ali haider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

SENG:312 Evening MUHAMMAD HUSSAIN

Programming Fundamentals
Data types

Lecture by Muhammad Hussain 1


Lecture by Muhammad Hussain 2
cout<< “hello “ ;

Lecture by Muhammad Hussain 3


cout<< “hello “ << ” SCA”;

Lecture by Muhammad Hussain 4


cout<< 2+ 2;

Lecture by Muhammad Hussain 5


cout<< variable1;

Lecture by Muhammad Hussain 6


cout<< variable1 << variable2;

Lecture by Muhammad Hussain 7


Lecture by Muhammad Hussain 8
Whitespace in C++

A line containing only whitespace,


possibly with a comment, is known as a
blank line, and C++ compiler totally
ignores it.

int age;

Lecture by Muhammad Hussain 9


Primitive Built-in Types
C++ offers the programmer a rich assortment of built-in
as well as user defined data types. Following table lists
down seven basic C++ data types

Lecture by Muhammad Hussain 10


Type Keyword
Integer int
Floating point float
Boolean bool
Character char
Double floating point double
Valueless void
Wide character wchar_t

Lecture by Muhammad Hussain 11


Several of the basic types can be modified using
one or more of these type modifiers −
signed
unsigned
short
Long

The following table shows the variable type, how


much memory it takes to store the value in
memory, and what is maximum and minimum
value which can be stored in such type of variables

Lecture by Muhammad Hussain 12


Type Typical Bit Width Typical Range
char 1byte -127 to 127 or 0 to 255
unsigned char 1byte 0 to 255
signed char 1byte -127 to 127
int 4bytes -2147483648 to 2147483647
unsigned int 4bytes 0 to 4294967295
signed int 4bytes -2147483648 to 2147483647
short int 2bytes -32768 to 32767
unsigned short int 2bytes 0 to 65,535
signed short int 2bytes -32768 to 32767
long int 4bytes -2,147,483,648 to 2,147,483,647
signed long int 8bytes same as long int
unsigned long int 4bytes 0 to 4,294,967,295
long long int 8bytes -(2^63) to (2^63)-1
unsigned long long int 8bytes 0 to 18,446,744,073,709,551,615
float 4bytes
double 8bytes
long double 12bytes
wchar_t 2 or 4 bytes 1 wide character

Lecture by Muhammad Hussain 13


Type Typical Bit Width Typical Range
int 4bytes -2147483648 to 2147483647
unsigned int 4bytes 0 to 4294967295
signed int 4bytes -2147483648 to 2147483647
short int 2bytes -32768 to 32767
unsigned short int 2bytes 0 to 65,535
signed short int 2bytes -32768 to 32767
long int 4bytes -2,147,483,648 to 2,147,483,647
signed long int 8bytes same as long int
unsigned long int 4bytes 0 to 4,294,967,295
long long int 8bytes -(2^63) to (2^63)-1
unsigned long long int 8bytes 0 to 18,446,744,073,709,551,615
float 4bytes
double 8bytes
long double 12bytes
wchar_t 2 or 4 bytes 1 wide character
char 1byte -127 to 127 or 0 to 255

Lecture by Muhammad Hussain 14


Sr.No Escape Sequence & Description
1 \t
Inserts a tab in the text at this point.

2 \b
Inserts a backspace in the text at this point.

3 \n
Inserts a newline in the text at this point.

4 \r
Inserts a carriage return in the text at this point.
5 \f
Inserts a form feed in the text at this point.
6 \’
Inserts a single quote character in the text at this point.
7 \”
Inserts a double quote character in the text at this point.
8 \\
Inserts a backslash character in the text at this point.

Lecture by Muhammad Hussain 15


cout << "Size of char : " << sizeof(char) << endl;
cout << "Size of int : " << sizeof(int) << endl;
cout << "Size of short int : " << sizeof(short int) << endl;
cout << "Size of long int : " << sizeof(long int) << endl;
cout << "Size of float : " << sizeof(float) << endl;
cout << "Size of double : " << sizeof(double) << endl;
cout << "Size of wchar_t : " << sizeof(wchar_t) << endl;

Size of char : 1
Size of int : 4
Size of short int : 2
Size of long int : 4
Size of float : 4
Size of double : 8
Size of wchar_t : 4

Lecture by Muhammad Hussain 16


{

char a=‘A’;
}

Lecture by Muhammad Hussain 17


{

char a=‘A’;
cout<< a;
}

Lecture by Muhammad Hussain 18


{

char a=‘/n’;
cout<< a;
}

Lecture by Muhammad Hussain 19


{

char a=64;
cout<< a;
}

Lecture by Muhammad Hussain 20


C++ Operators
An operator is simply a symbol that is used to perform operations.

There can be many types of operations like arithmetic, logical, bitwise etc.
There are following types of operators to perform different types of
operations in C language.

• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operator
• Unary operator
• Ternary or Conditional Operator
• Misc Operator

Lecture by Muhammad Hussain 21


Lecture by Muhammad Hussain 22

You might also like