Data Types

 Data Types in C

Data Types

A data type specifies that what type of data a variable can store such as integer, floating, character, etc. Each data type has a specific range of values and operations that can be performed on it.

Types of Data Types :

i. Primary Data Type / Basic Data type - Integer, Floating, Character.

ii. Derived Data type - Arrays, Ponters, Union, Structure

iii. User Defined Data Type - Enum, Typedef, etc.

a. Integer Data Types:

int res = 5;
  

int: Used to store whole numbers (positive or negative) without decimal points. It has a size of 4 bytes.

short: Used to store smaller whole numbers, with a size of 2 bytes.

long: Used to store larger whole numbers, with a size of 4 bytes or more.

long long: Used to store very longer integers.

char: Used to store single characters, such as letters or symbols.

b. Floating-Point Data Types:

float avg = 50.26;

• float: Used to store floating-point numbers (real numbers) with single precision. It typically has a size of 4 bytes.

• double: Used to store floating-point numbers with double precision. It typically has a size of 8 bytes.

• long double: Used to store extend-precision floating-point.

• Void Type: void: Represents the absence of any type. It is commonly used as a return type for functions that does not return any value.

ii. Derived Types:

Arrays: A collection of elements of the same type, accessed by an index.

Pointers: Variables that store memory addresses instead of actual values.

Structures: User-defined data types that can contain multiple variables with different types.

iii. User Defined / Enumeration Data Type: 

• Enumeration data types in c programming language allow you to define your own set of named values. To define the enumeration data type in c programming language you use the 'enum' keyword.

enum Day{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};

Here's an example demonstrating the usage of different data types in C:

#include <stdio.h>
int main() {
    int age = 25;
    float height = 1.75;
    char grade = 'A';
    printf("Age: %d\n", age);
    printf("Height: %.2f\n", height);
    printf("Grade: %c\n", grade);
    return 0;
}

In this example, we declare variables age of type int, height of type float, and grade of type char. We then assign values to these variables and print them using the printf function.

Size , Range, Format Specifier:

Size, Range

Thanks For Visiting😊