Oop 1.3
Oop 1.3
2. Declaration of Variables
3. Constants
5. Reference variable
6. Type Compatibility
double 8 byte
C++ Datatypes
• variable might be belonging to any of the data type like int, float, char etc.
• Syntax:
datatype variable_list;
#define
#define identifier
identifier name
name value value
• Reference variable are important for working with objects & creating dynamic,flexible
programs.
• Unlike primitive data types that hold their values directly, reference variables store the
address of the object they refer to, enabling the manipulation of objects through these
references.
• Type compatibility is use to convert two different data type variables into a single data type to
solve mathematical and logical expressions easily without any data loss.
• Example:
• int a= 10.5;
• No data loss.
• Loss of memory is there as higher data type is converted into lower data type.
• Explicit type conversion in C++ is the process of manually converting one data
type to another data type using casting operators.
• Syntax:
Datatype variable_name=(datatype) variable_name;
Program of explicit type conversion :
Write a program to accept one value as double int data type and explicitly convert it into integer and print the
result.
#include<iostream.h>
#include<conio.h>
int main() OUTPUT
{ Enter one double value:56.7
clrscr(); Value of double value is:56.7
double d; Value of integer value is:56
cout<<“Enter one double value:”;
cin>>d;
int a=(int)d;
cout<<“ value of double value is:”<<d;
cout<<“value of integer value is:”<<a;
return 0;
};
THANK YOU