0% found this document useful (0 votes)
36 views5 pages

Lecture - 3 Data Types

The document provides an overview of data types in the C programming language, detailing basic built-in types such as int, float, char, and void, as well as more complex types like arrays, pointers, enums, structs, and unions. It explains the purpose and characteristics of each type, including their memory allocation and usage. Additionally, it highlights the differences between structures and unions in terms of memory space and member access.

Uploaded by

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

Lecture - 3 Data Types

The document provides an overview of data types in the C programming language, detailing basic built-in types such as int, float, char, and void, as well as more complex types like arrays, pointers, enums, structs, and unions. It explains the purpose and characteristics of each type, including their memory allocation and usage. Additionally, it highlights the differences between structures and unions in terms of memory space and member access.

Uploaded by

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

Data Types

C has a concept of 'data types' which are used to define a variable before its use. The definition of a
variable will assign storage for the variable and define the type of data that will be held in the location.
The value of a variable can be changed any time. The data types are the core building blocks in C.

C has the following basic built-in data types.

int
float
char
void

In general the overall data types are used in C/C++ are here:
int (Integer)
unsigned int
l
long
unsigned long
long long int
float
double
long double
char (Character)
unsigned char
array
pointer
enum (Enumeration)
struct (Structure)
union

Data Types Range

int - data type

int is used to define integer numbers.

int Count;

Count = 5;

float - data type

float is used to define floating point numbers.


{

float Miles;

Miles = 5.6;

The float type has a precision up to 7 digits. The double data type has a precision up to 15 digits.

char - data type

char defines characters.

char Letter;

Letter = 'x';

void type

void type means no value. This is usually used to specify the type of functions which returns nothing. Void
can be as follows:

void main()

Array

An array is a collection of data items, all of the same type, accessed using a common name.

Array works on integer and character value and can be declared as

type array_name [array_size]

Pointers

A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory
location. Like any variable or constant, you must declare a pointer before using it to store any variable
address. The general form of a pointer variable declaration is as follows:

type *var_name
Enum (Enumeration)

Enumeration is a user defined datatype in C language. It is used to assign names to the integral constants
which make a program easy to read and maintain. The enum is used for values that are not going to
change (e.g., days of the week, colors in a rainbow, number of cards in a deck, etc.

enum day {

Saturday, Sunday, Monday, Tuesday, Thursday, Friday

};

Structure (struct)

Structure is a user-defined datatype in C language which allows us to combine data of different types
together. Structure helps to construct a complex data type which is more meaningful. It is somewhat
similar to an Array, but an array holds data of similar type only. But structure on the other hand, can
store data of any type, which is practical more useful.

struct Student

char name[25];

int age;

char branch[10];

char gender;

};

Union

A union is a data type which has all values under it stored at a single address. It is a special data type
available in C that allows storing different data types in the same memory location. You can define
a union with many members, but only one member can contain a value at any given time. Unions provide
an efficient way of using the same memory location for multiple-purpose

union car

char name[50];

int price;

}
Difference Between Structure and Union In C:

C Structure C Union

Union allocates one common storage space for all its


Structure allocates storage space for all its members.Union finds that which of its member needs high
members separately. storage space over other members and allocates that much
space

Structure occupies higher memory space. Union occupies lower memory space over structure.

We can access all members of structure at a


We can access only one member of union at a time.
time.

Structure example:struct student{int Union example:union student{int mark;char


mark;char name[6];double average;}; name[6];double average;};

You might also like