C Datatypes Explained with Flowcharts and Examples – MPS

In this C programming class, we’ll see all obtainable C datatypes, clarify their goal and the boundaries. You’ll see flowcharts and code examples to grasp higher.

The information varieties are the core constructing blocks in C. Hence, please learn with full focus and focus.

1. What are Datatypes in C Programming?

In C programming lang, information varieties are simply identified what their identity suggests. They characterize the sort of information to retailers. They are used to declare a number of capabilities as effectively as variables in a program.
There are primarily three classes of information varieties, Basic/Primitive, Derived, User-Defined

C Datatypes to Use in Programs
C Datatypes to Use in Programs

Now, we’ll see what every one of them means individually.

Int datatype

It is used to retailer the integer information kind.

The common integer that we use has a dimension of 2 bytes (16 bits) on a 16-bit machine. However, many of the fashionable programs have 32 or 64-bit configurations. The dimension of an integer in such a setting is 4 bytes with a beginning worth of -2,147,483,648 and an ending worth of 2,147,483,647. Any operations involving a quantity out of this vary will return both rubbish or an error.

Note: Garbage worth is nothing however waste or unused information in a program’s reminiscence. It may be associated with variables that are now not in use. So, it is all the time greatest to initialize to keep away from any undefined conduct.

Unsigned int

An integer may be of an unsigned kind. Such a sort (unsigned int) on 32-bit may have a variety from 0 to 4,294,967,295 and 0 to 65535 on a 16-bit system.

Long datatype

It additionally shops the integer information with a better vary. The long kind is 4 bytes in 32-bit programs and 8 bytes in 64-bit setups.

The 32-bit long vary is similar as an integer while on 64-bit, it could possibly maintain a minimal of -9,223,372,036,854,775,808 and goes as much as 9,223,372,036,854,775,807.

Unsigned long

In some cases, we require solely optimistic numeric values; then it’s higher to make use of the unsigned kind. It does not solely make certain that you just get one but in addition, enhances the vary.

The unsigned long is 4 bytes and ranges from 0 to 4,294,967,295.

Float datatype

This datatype is additionally numeric however permits numbers with decimal locations. It has a dimension of 4 bytes and has a variety of 3.4E-38 to three.4E+38.

The float kind has a precision of as much as 7 digits.

Double datatype

It is similar to float however with a better precision vary that is 8 bytes which provides it a capability to retail extra numerals after the decimal locations, double to be precise.

It has a size of 8 bytes and has a variety of 1.7E +/- 308. The double information kind has a precision of as much as 15 digits.

Char datatypes

Char information kind by default permits a single character such as a letter from the alphabet. It has a scale of simply 1 byte with a variety of -128 to 127 or 0 to 255.

However, with an array [] suffix, it could possibly maintain string values, a mix of alphanumeric characters.

Unsigned char

Also, there is an unsigned char kind that is comparable however doesn’t permit the (-ve) values. It has an identical dimension of 1 byte with a variety of 0 to 255.

Short datatype

The size of the short kind is two bytes. It permits the vary of values equal to 2 to the ability 16, i.e., as much as 16 bits. Since it is a signed one, therefore, incorporates each the optimistic and adverse values.

It has a variety of values between -32768 and 32767.

Unsigned short

The unsigned short kind incorporates solely +ve numbers and additionally has a dimension of two bytes. It can retailer a minimal worth of 0 and goes as much as most of 65 535.

Array datatype

A C array is a contiguous sequence of parts of a comparable information kind. It is primarily to create a group of the primitives just like the numbers, chars, struct, and unions.

We have a devoted chapter for the Arrays which you’ll be able to undergo later.

Pointers datatype

Pointers are used to level and entry the values saved at an deal with in this system’s dynamic reminiscence identified as the heap.

The pointer kind variables get saved on the heap while the opposite varieties on the stack.

Like an array can have a number of parts, the pointer can also maintain a number of values relying upon the quantity of reminiscence it will get allotted.

This information kind additionally has a chapter devoted to it so we’ll see extra of it later.

Enum datatype

The enum is used to assign a reputation to a variable to a relentless. We may even are in additional chapters.

Structure (struct)

The construction kind is used to create a knowledge kind that may maintain a number of information varieties in it.

Union datatype

A union is a knowledge kind that has all values below it saved at a single deal with.

In the under C datatypes instance, we’ll see using the 2 elementary C datatypes.

2. Data Types Range and Sizes

We’ve captured all the basic C data types alongside their dimension in bytes and the vary of values under the desk.

C Datatypes Range and Sizes
C Datatypes Range and Sizes

2. Sample Program: Print Quotient of Two Numbers

In this instance, we’ll carry out the arithmetic division operation on two integer numbers. After that, the identical end result will get assigned to 2 variables of the next varieties.

Let’s first perceive the circulation of this program with the assistance of its flowchart.

Flowchart:

Get Quotient of Two Integers - Flowchart

Algorithm:

Step 1: Start.

Step 2: Initialize a variables.

Step 3: Take enter from the consumer.

Step 4: Get the quotient z =d=x / y

Step 5: Print output of the integer as effectively as the float.

Step 6: Stop.

Code:

#include<stdio.h>
#include<conio.h>

void main()
{
    int x, y, z;
    float d;

    printf("Enter two numbers to divide : \n");
    scanf("%d %d", &x, &y);

    z = x/y;
    d = x/y;

    printf("Quotient of %d and %d in the form of int is %d",x , y, z);
    printf("Quotient of %d and %d in the form of float is %f",x ,y ,d);
    getch();
}

Note: float information kind is declared in print utilizing %f simply as the int is declared utilizing %d.

The output ought to look one thing like this.

C Datatypes Program Output
C Datatypes Program Output

Note: If we use the double kind, then it will additionally give the identical output, however, it will matter for packages the place accuracy is wanted.

We have simply coated the fundamentals right here. You shall be taught extra concerning the information varieties and their superior utilization in the subsequent C programming tutorials

Related Posts

Pramod Kumar Yadav is from Janakpur Dham, Nepal. He was born on December 23, 1994, and has one elder brother and two elder sisters. He completed his education at various schools and colleges in Nepal and completed a degree in Computer Science Engineering from MITS in Andhra Pradesh, India. Pramod has worked as the owner of RC Educational Foundation Pvt Ltd, a teacher, and an Educational Consultant, and is currently working as an Engineer and Digital Marketer.



Leave a Comment