Data Types of C language

Safalta Expert Published by: Saksham Chauhan Updated Wed, 22 Feb 2023 06:33 PM IST

Highlights

Check the Data Types of C language Here At Safalta.com

In our previous blog we learn about the introduction of C Programming, In this blog we will get to know about the Data Types Of C language. For the previous blog you can check the link below 'Introduction of C Programming'. Data types define the semantics and properties of data element storage in the C programming language. They take the form of declarations for variables or memory locations in the language syntax. The kinds of operations or procedures used to process data pieces are also determined by data types. The C programming language offers syntax to create array and compound kinds as well as fundamental arithmetic types like integer and real number types. Headers for the C standard library contain definitions of support types that have extra attributes, such as providing storage with a precise size, independent of the language implementation on particular hardware systems. These definitions are to be utilised via include directives. 

Source: Safalta.com


Download these FREE Ebooks:
1. Introduction to Digital Marketing
2. Website Planning and Creation

Main Data Types in C

Every element in C does have a corresponding data type. Each data type has a different set of operations that may be performed on it as well as different memory needs. Let's quickly go through each one:

Free Demo Classes

Register here for Free Demo Classes


Here are some examples of some of the most common data types used in C:
  • Char is the most basic data type in C. It saves a single character and utilises a single byte of memory in almost all compilers.
  • An integer is stored in an int variable, as its name indicates.
  • Floating point numbers with decimal values are stored as only one floats.
  • Double-precision decimal integers are stored inside it (numbers with floating point values).
Additionally, the ranges that various data types may store numbers can vary. These ranges could change depending on the compiler. The list of 32 bit gcc compiler ranges, together with the memory need and format specifiers, are shown below.
 
Data Type 
 
Memory (bytes) 
 
Range 
 
Format Specifier 
 
short int 
 

 
-32,768 to 32,767 
 
%hd 
 
unsigned short int 
 

 
0 to 65,535 
 
%hu 
 
unsigned int 
 

 
0 to 4,294,967,295 
 
%u 
 
int 
 

 
-2,147,483,648 to 2,147,483,647 
 
%d 
 
long int 
 

 
-2,147,483,648 to 2,147,483,647 
 
%ld 
 
unsigned long int 
 

 
0 to 4,294,967,295 
 
%lu 
 
long long int 
 

 
-(2^63) to (2^63)-1 
 
%lld 
 
unsigned long long int 
 

 
0 to 18,446,744,073,709,551,615 
 
%llu 
 
signed char 
 

 
-128 to 127 
 
%c 
 
unsigned char 
 

 
0 to 255 
 
%c 
 
float 
 

 
  %f 
 
double 
 

 
  %lf 
 
long double 
 
16 
 
  %Lf 

For Example:

#include
int main()
{
    int a = 1;
    char b = 'G';
    double c = 3.14;
    printf("Hello World!\n");

    // printing the variables defined
    // above along with their sizes
    printf("Hello! I am a character. My value is %c and "
        "my size is %lu byte.\n",
        b, sizeof(char));
    // can use sizeof(b) above as well

    printf("Hello! I am an integer. My value is %d and "
        "my size is %lu bytes.\n",
        a, sizeof(int));
    // can use sizeof(a) above as well

    printf("Hello! I am a double floating point variable."
        " My value is %lf and my size is %lu bytes.\n",
        c, sizeof(double));
    // can use sizeof(c) above as well

    printf("Bye! Take care. :)\n");

    return 0;
}
 
  Output: 







 

Related Article

Unlock the Power of Advanced Excel Tools: A Complete Guide

Read More

Microsoft Office suite Basics to Word, Excel, and PowerPoint

Read More

10 Best Digital Marketing Project Ideas

Read More

Techniques for improving website visibilty on search engins

Read More

A complete Guide for Mastering Docs, Sheets, and Slides

Read More

Best practices for building and maintaining an effective email marketing campaign

Read More

Introduction to Python Programming And SQL for Data Management

Read More

How influencers can help brands reach their target audience and drive conversions

Read More

Top CRM Tools and How to Pick the Best CRM for Your Team

Read More