CP Practical-2
CP Practical-2
DataType :-
Each variable in C has an associated data type. It specifies the type of data that the variable
can store like integer, character, floating, double, etc. Each data type requires different
amounts of memory and has some specific operations which can be performed over it. The
data type is a collection of data with values having fixed values.
Types Description
Primitive Data Primitive data types are the most basic data types that are used for
Types representing simple values such as integers, float, characters, etc.
User Defined
The user-defined data types are defined by the user himself.
Data Types
The data types that are derived from the primitive or built-in datatypes
Derived Types
are referred to as Derived Data Types.
Data Casting in C
Data casting is the process of converting one data type to another. There are two types of
casting in C:
This happens automatically when you assign a value of one type to a variable of another type.
Example:
int i = 10;
double d = i; // Implicitly casts 'int' to 'double'
Example:
double d = 10.5;
int i = (int) d; // Explicitly casts 'double' to 'int'
Examples of Type Casting
Example 1: Implicit Casting
#include <stdio.h>
#include<conio.h>
void main()
{
int i = 42;
double d = i; // Implicit cast from int to double
clrscr();
#include <stdio.h>
#include<conio.h>
void main()
{
// Given a & b
int a = 15, b = 2;
float div;
// Division of a and b
div = a / b;
return 0;
}