C Datatypes Explained with Flowcharts and Examples – MPS

In this C programming class, we’ll cowl 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.

Table of Content

C Datatypes – Let’s Understand from Scratch

1. What are Datatypes in C Programming?

In C programming, information varieties are simply the identical what their identify suggests. They characterize the sort of information to retailer. 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.

This diagram would aid you.

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

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

1.1. Int

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 setting is 4 bytes with a beginning worth of -2,147,483,648 and an ending worth as 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 to variables that are now not in use. So, it is all the time greatest to initialize to keep away from any undefined conduct.

1.2. 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.

1.3. Long

It additionally shops the integer information with a better vary. The long kind is 4 bytes on 32-bit programs and of 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.

1.4. Unsigned long

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

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

1.5. Float

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 as much as 7 digits.

1.6. Double

It is similar as float however with a better precision vary that is 8 bytes which provides it a capability to retailer 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 as much as 15 digits.

1.7. Char

Char information kind by default permits a single character such as a letter from the alphabet. It has the 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 alpha-numeric characters.

1.8. Unsigned char

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

1.9. Short

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.

1.10. 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 a most of 65 535.

1.11. Array

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.

1.12. Pointers

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.

1.13. Enum

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

1.14. Structure (struct)

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

1.15. Union

A union is a knowledge kind which 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 datatypes alongside with their dimension in bytes and the vary of values in the under 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.

2.1. Flowchart:

Get Quotient of Two Integers - Flowchart

2.2. Algorithm:

Step 1: Start.

Step 2: Initialize variables.

Step 3: Take enter from the consumer.

Step 4: Get the quotient c=d=a/b

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

Step 6: Stop.

2.3. Code:


void fundamental()

    int a, b, c;
    float d;

    printf("Enter two numbers to divide : n");
    scanf("%d %d", &a, &b);

    c = a/b;
    d = a/b;

    printf("Quotient of %d and %d in the form of int is %d",a , b, c);
    printf("nQuotient of %d and %d in the form of float is %f",a ,b ,d);


Note: float information kind is declared in printf 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.

Python  Recommended Post

Source hyperlink

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *


You have successfully subscribed to myprogrammingschool

There was an error while trying to send your request. Please try again.

My Programming School will use the information you provide on this form to be in touch with you and to provide updates and marketing.