Data Types in C | Set 1

Last Updated :

Data types define the type of data a variable can hold. C language has some predefined set of data types to handle various kinds of data that we can use in our program. These datatypes have different storage capacities.

In C programming, data types are declarations for variables. This determines the type and size of data associated with variables. For example,

int VarName ;

Here, VarName is a variable name and it has type of integer (int).

Category of C Data Types :

Data types in C++ are categorised in three groups: Built-In, Derived, and User Defined Data type.

1. Built-In Data Types :
Built-in data types are the most basic data-types in C. The term built-in means that they are pre-defined in C and can be used directly in a program. char, int, float and double are the most common built-in data types. Apart from these, we also have void and bool data types.

 

Data Type Explanation Example
int To represent integer type values. This has 2 bytes in size. int a = 10;
char To represent character type values. This has 1 bytes in size. char name = ‘A’;
float It is used to store decimal numbers (numbers with floating point value) with single precision. This has 4 bytes in size. float x = 3.14;
double It is used to store decimal numbers (numbers with floating point value) with double precision. This has 8 bytes in size. double num = 10801.98018;
boolean double num = 10098.98899; bool y = true;
void It holds no value. If the function has a void type, it means that the function will not return any value. void foo();

 

Notes –
There are 5 modifiers available in C language. They are: short, long, signed, unsigned, long long.

2. Derived Data Types :
Derived data types are nothing but primary datatypes but a little twisted or grouped together like array, stucture, union and pointer. These are : array, function, and pointers.

  1. Array data type –
    Array can store similar type of data types in contiguous manner. They can be used to store collection of primitive data types such as int, float, double, char, etc of any particular type. Example –

    int a = {10, 20, 30};
  2. Function data type –
    These are used to represent type of function in C. They can be used to store collection of primitive data types such as int, float, double, char, etc of any particular type. Example –

    int foo (int a, int b);
  3. Pointers –
    These are powerful C features which are used to access the memory and deal with their addresses. Example –

    int a;
    int *b = &a;

    Function pointers allow referencing functions with a particular signature.

3. User Defined Data Types :
We can define our own data type using ‘type definition’ in C language. There are three such types : Structure, union, and enum.

  1. Structure Data Type –
    A structure creates a data type that can be used to group items of possibly different types into a single type. “struct” keyword is used to define a structure. Example –

    struct address 
    { 
       char name[50]; 
       char street[100]; 
       char city[50]; 
       char state[20]; 
       int pin; 
    };
  2. Union Data Type –
    Like Structures, union is a user defined data type. In union, all members share the same memory location. “union” keyword is used to define a structure. Example –

    union address 
    { 
       char name[50]; 
       char street[100]; 
       char city[50]; 
       char state[20]; 
       int pin; 
    };
  3. Enumeration Data Type –
    It is used to assign names to the integral constants which makes a program easy to read and maintain. The keyword “enum” is used to declare an enumeration. Example –

    enum week{Mon, Tue, Wed}day;

Read next related article – Data Types in C | Set 2

Please write comments if you find anything incorrect. A gentle request to share this topic on your social media profile.

Comment
Next Article
CPP_Programmer Published 21 Aug, 2020 · 4 min read
Article Tags :

Similar Reads

  • What should we use void main() or int main() ?

    There is question that what should we use void main() or int main() ? void main() { /* ... */ } Or, int main() { /* ... */…

    2 min read
  • C Comments

    Prerequisite – C Language Introduction C comments explain code and improve readability. These do not affect program execution. You can use comments in C to clarify code and describe…

    1 min read
  • C Programming Language Standard

    Prerequisite – C Language Introduction The C programming language has various versions: C89/C90, C99, C11, and C18. C89/C90: Released in 1989/1990. It introduced key language features. C99: This…

    2 min read
  • Features of C Programming Language

    Prerequisite – C Language Introduction C is a simple language made in 1972 by Dennis Ritchie. It’s for system programming. C has low-level memory access, basic keywords, good…

    1 min read
  • C Language Introduction

    C is a programming language developed by Dennis Ritchie in 1972. It has a significant historical impact. It was originally created at Bell Laboratories of AT&T Labs for…

    4 min read
  • Code editors

    Code editors are where programmers spend most of their time. There are two main types of code editors: IDEs and Lightweight editors. IDEs (Integrated Development Environments) IDEs (Integrated…

    1 min read