Sei sulla pagina 1di 13

DAY3

User-defined Data Types


Structure Union Class

Built-In Data Types


Integral int, float
Void

Derived Data Types


Array
Function Pointer

Float, double

Enumeration

Reference

Data Types
Type Typical Bit Width Typical Range

signed char int unsigned int


signed int short int unsigned short int signed short int

1byte 4bytes 4bytes


4bytes 2bytes Range Range

-127 to 127
-2147483648 to 2147483647

0 to 4294967295
-2147483648 to 2147483647 -32768 to 32767 0 to 65,535 -32768 to 32767

Type
long int signed long int unsigned long int float double

Typical Bit Width


4bytes 4bytes 4bytes 4bytes 8bytes

Typical Range
-2,147,483,647 to 2,147,483,647 same as long int 0 to 4,294,967,295 +/- 3.4e +/- 38 (~7 digits) +/- 1.7e +/- 308 (~15 digits)

long double
char unsigned char

8bytes
1byte 1byte

+/- 1.7e +/- 308 (~15 digits)


-127 to 127 or 0 to 255 0 to 255

INPUT/OUTPUT (I/O)
C++ supports input/output statements which can be used to feed new data into the computer or obtain output on an output device such as: VDU, printer etc.
The following C++ stream objects can be used for the input/output purpose. 1. cin - console input 2. cout - console output

Output Operator
The statement [cout << C++ is better than C;] causes the string in quotation marks to be displayed on the screen. cout is a predefined object that represents the standard output stream in C++.
The operator << is called insertion operator inserts the contents of the variable on its right side to the object on its left. Cout << varname;

Input Operator
The statement [cin >> num1 ] is an input statement and causes the program to wait for user input for a number.
The >> operator is called Extraction operator

Declaration of Variable
C++ allows the declaration of variable anywhere in the scope.
A variable can be declared right at the place of its first use

Program N0 5 : Addition of two numbers

Dynamic Initialization of Variable


C++ permits initialization of variable at run time.
This is referred as Dynamic Initialization of variable A variable can be initialized at run time using expressions at the place of declaration Ex.
float area = 3.14159 * rad * rad

Program No. 6: Calculate Area of Circle

Program NO. 7 : Input Price, Qty and calculate bill amount with discount of 5.00% if price is greater than 50

Program No. 8
Input a number and display factorial value using loop statement Factorial : A factorial of a nonnegative number n is the product of all positive integers less than or equal to n

Potrebbero piacerti anche