Data types in c | Bkhakt Kavi Narsinh Mehta University Junagadh | BKNMU

 

In the C programming language, data types define the type of data that a variable can hold. C provides several built-in data types, which can be categorized into the following main groups:

Basic Data Types:

int: Represents integer values, which can be either signed or unsigned.
char: Represents a single character or a small integer value.
float: Represents single-precision floating-point numbers.
double: Represents double-precision floating-point numbers.
void: Represents the absence of a type or a pointer to an unknown type.
Enumeration Data Type:

enum: Defines a user-defined data type consisting of a set of named integer constants.
Derived Data Types:

array: Represents a collection of elements of the same data type.
pointer: Represents a variable that stores the memory address of another variable.
structure (struct): Represents a user-defined composite data type that groups together variables of different data types under a single name.
union: Represents a user-defined composite data type that allows different data types to be stored in the same memory location.
Typedef Data Type:

typedef: Allows you to create an alias for an existing data type. It helps improve code readability and maintainability.
User-Defined Data Types:

C allows you to create your own user-defined data types using struct, enum, and typedef. This allows you to define custom data structures and enumerations as per your requirements.
Here are some examples of how these data types are used:


int integerVariable = 42;
char characterVariable = 'A';
float floatVariable = 3.14;
double doubleVariable = 2.718;
enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
typedef int customType;
struct Point {
    int x;
    int y;
};
union Variant {
    int intValue;
    float floatValue;
    char charValue;
};
int main() {
    customType myValue = 100;
    struct Point myPoint;
    myPoint.x = 5;
    myPoint.y = 10;
    union Variant myVariant;
    myVariant.intValue = 42;
    return 0;
}


Post a Comment

Thanks for comment.

Previous Post Next Post