0% found this document useful (0 votes)
38 views15 pages

Datatypes in C

The document discusses data types in C programming. It covers: 1) Data types specify the type of data a variable can store, such as integer, character, floating, and double. Each data type requires a different amount of memory and has specific operations. 2) There are primitive, derived, and user-defined data types in C. Primitive types include integer, character, float, and double. Derived types are built from primitive types, like arrays and pointers. User-defined types are created by the programmer. 3) Example programs demonstrate using different data types like characters, integers, arrays, and pointers in C code.

Uploaded by

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

Datatypes in C

The document discusses data types in C programming. It covers: 1) Data types specify the type of data a variable can store, such as integer, character, floating, and double. Each data type requires a different amount of memory and has specific operations. 2) There are primitive, derived, and user-defined data types in C. Primitive types include integer, character, float, and double. Derived types are built from primitive types, like arrays and pointers. User-defined types are created by the programmer. 3) Example programs demonstrate using different data types like characters, integers, arrays, and pointers in C code.

Uploaded by

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

Data Types in C

What is Datatype?

01 02 03 04

The data type is a It specifies the type of Each data type requires different Each variable in C

collection of data data that the variable amounts of memory and has has an associated

with values having can store like integer, some specific operations which data type.

fixed values, character, floating, can be performed over it.

meaning as well as double, etc.

its characteristics.
01

Types of
Datatypes in C
Primitive Data Types
Primitive data types are the most basic data types that are used for
representing simple values such as integers, float, characters, etc.

User Defined Data Types


The user-defined data types are defined by the user himself.

Derived Types
The data types that are derived from the primitive or built-in
datatypes are referred to as Derived Data Types.
Types of Primitive Datatypes in C
Integer Data Type Character Data Type

The integer datatype in C is used to store Character data type allows its variable to store

the integer numbers. only a single character. The size of the character

Range: −32,768 to 32,767 is 1 byte. It is the most basic data type in C.

Size: 2 bytes Range: -128 to 127

Format Specifier: %d Size: 1 byte


Format Specifier: %c

Float Data Type Double Data Type

In C programming float data type is used A Double data type in C is used to store
to store floating-point values. Float in C is decimal numbers with double precision. It is
used to store decimal and exponential used to define numeric values which hold
values. numbers with decimal values in C.
Size: 4 bytes Size: 8 bytes
Format Specifier: %f Format Specifier: %lf
Types of Derived Datatypes in C

Array Data Type Pointer Data Type

An array, a derived data type, lets you A pointer is a derived data type that keeps track

store a sequence of fixed-size elements of of another data type's memory address. Pointers

the same type. It provides a mechanism are commonly used in tasks such as function

for joining multiple targets of the same pointers, data structures, and dynamic memory

data under the same name. allocation.


Types of User Defined Datatypes 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.

Structure Data Type Union Data Type

A derived data type called a union enables you


A structure is a derived data type that
to store various data types in the same
enables the creation of composite data
memory address. In contrast to structures,
types by allowing the grouping of many
where each member has a separate memory
data types under a single name.
space, members of a union all share a single
memory space.
02

Programs
P
O
I
N
T
E
R
S

Output:
Value of num: 42
VOID

Output:

Hello, world!
Processing input...
Value of number: 10
#include <stdio.h>

int main()
{ CHAR
// Initializing different characters and displaying them
char a = 'B';
printf("character a = %c\n",a); Output:

char b = 'a'; character a = B


character b = a
printf("character b = %c\n",b);
character c = 0

char c = '0';
printf("character c = %c\n",c);

return 0;
}
#include <stdio.h>
int main()
{ INTEGER
// Integer value with positive data.
int a = 9;
// integer value with negative data. Output:
int b = -9;
Integer value with positive data: 9
Integer value with negative data: -9
printf("Integer value with positive data: %d\n", a);
printf("Integer value with negative data: %d\n", b);

return 0;
}
#include <stdio.h>
int main()
{
int numbers[5]; // Declares an integer array with a size of 5 elements ARRAY
// Assign values to the array elements
numbers[0] = 10;
numbers[1] = 20;
Output:
numbers[2] = 30;
numbers[3] = 40; Values in the array: 10 20 30 40 50
numbers[4] = 50;
// Display the values stored in the array
printf("Values in the array: ");
for (int i = 0; i < 5; i++) {
printf("%d ", numbers[i]);
}
printf("\n");

return 0;
}
THANK YOU

You might also like