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

Data Types in C

Uploaded by

Mohamt
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 views10 pages

Data Types in C

Uploaded by

Mohamt
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/ 10

Data Types in C

A data type specifies the type of data that a variable can store such
as integer, floating, character, etc.

There are the following data types in C language.


Basic Data Types
The basic data types are integer-based and floa�ng-point-based. C language
supports both signed and unsigned literals.
The memory size of the basic data types may change according to 32 or 64-bit
opera�ng systems.

Let's see the basic data types. Its size is given according to 32-bit architecture.
Int:
Integers are entire numbers without any fractional or decimal parts, and the int data
type is used to represent them.

It is frequently applied to variables that include values, such as counts, indices, or other
numerical numbers. The int data type may represent both positive and negative
numbers because it is signed by default.

An int takes up 4 bytes of memory on most devices, allowing it to store values between
around -2 billion and +2 billion.

Char:
Individual characters are represented by the char data type. Typically used to
hold ASCII or UTF-8 encoding scheme characters, such as letters, numbers, symbols,
or commas. There are 256 characters that can be represented by a single char, which
takes up one byte of memory. Characters such as 'A', 'b', '5', or '$' are enclosed in single
quotes.

Float:
To represent integers, use the floating data type. Floating numbers can be used to
represent fractional units or numbers with decimal places.

The float type is usually used for variables that require very good precision but may not
be very precise. It can store values with an accuracy of about 6 decimal places and a
range of about 3.4 x 1038 in 4 bytes of memory.

Double:
Use two data types to represent two floating integers. When additional precision is
needed, such as in scientific calculations or financial applications, it provides greater
accuracy compared to float.

Double type, which uses 8 bytes of memory and has an accuracy of about 15 decimal
places, yields larger values. C treats floating point numbers as doubles by default if no
explicit type is supplied.
In the Example, we declare four variables: an int variable for the
person's age, a char variable for the student's grade, a float
variable for the temperature reading, and two variables for
the number pi.
Derived Data Type
C also supports derived data types, including arrays, pointers, structures, and unions.
These data types give programmers the ability to handle heterogeneous data, directly
modify memory, and build complicated data structures.

Array:
An array, a derived data type, lets you store a sequence of fixed-size elements of the
same type. It provides a mechanism for joining multiple targets of the same data under
the same name.

The index is used to access the elements of the array, with a 0 index for the first entry.
The size of the array is fixed at declaration time and cannot be changed during program
execution. The array components are placed in adjacent memory regions.

Example of how to define and use a Array in C:


Pointer:

A pointer is a derived data type that keeps track of another data type's
memory address. When a pointer is declared, the data type it refers to
is stated first, and then the variable name is preceded by an asterisk (*).

You can have incorrect access and change the value of variable using pointers
by specifying the memory address of the variable. Pointers are commonly
used in tasks such as function pointers, data structures, and dynamic
memory allocation.

Example of how to define and use a Pointer in C:


AD
Structure:
A structure is a derived data type that enables the creation of composite data types by
allowing the grouping of many data types under a single name. It gives you the ability to
create your own unique data structures by fusing together variables of various sorts.

• A structure's members or fields are used to refer to each variable within it.
• Any data type, including different structures, can be a member of a structure.
• A structure's members can be accessed by using the dot (.) operator.

Example of how to define and use a Structure in C:


Union:
A derived data type called a union enables you to store various data types in the same
memory address. In contrast to structures, where each member has a separate memory
space, members of a union all share a single memory space. A value can only be held by
one member of a union at any given moment. When you need to represent many data
types interchangeably, unions come in handy.

Example of how to define and use a union in C:


Enumeration Data Type
A set of named constants or enumerators that represent a collection of connected values
can be defined in C using the enumeration data type (enum). Enumerations give you
the means to give names that make sense to a group of integral values, which makes your
code easier to read and maintain.

Example of how to define and use an enumera�on in C:


Void Data Type
The void data type in the C language is used to denote the lack of a particular
type. Function return types, function parameters, and pointers are three situations
where it is frequently utilized.

Function Return Type:


A void return type function does not produce a value. A void function executes a task
or action and ends rather than returning a value.

Example:

Function Parameters:
The parameter void can be used to indicate that a function accepts no arguments.

Example:

Pointers:
Any address can be stored in a pointer of type void*, making it a universal pointer. It
offers a method for working with pointers to ambiguous or atypical types.

Example:

Ahmed Mostafa

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy