TechBeamersTechBeamers
  • Learn ProgrammingLearn Programming
    • Python Programming
      • Python Basic
      • Python OOP
      • Python Pandas
      • Python PIP
      • Python Advanced
      • Python Selenium
    • Python Examples
    • Selenium Tutorials
      • Selenium with Java
      • Selenium with Python
    • Software Testing Tutorials
    • Java Programming
      • Java Basic
      • Java Flow Control
      • Java OOP
    • C Programming
    • Linux Commands
    • MySQL Commands
    • Agile in Software
    • AngularJS Guides
    • Android Tutorials
  • Interview PrepInterview Prep
    • SQL Interview Questions
    • Testing Interview Q&A
    • Python Interview Q&A
    • Selenium Interview Q&A
    • C Sharp Interview Q&A
    • PHP Interview Questions
    • Java Interview Questions
    • Web Development Q&A
  • Self AssessmentSelf Assessment
    • Python Test
    • Java Online Test
    • Selenium Quiz
    • Testing Quiz
    • HTML CSS Quiz
    • Shell Script Test
    • C/C++ Coding Test
Search
  • Python Multiline String
  • Python Multiline Comment
  • Python Iterate String
  • Python Dictionary
  • Python Lists
  • Python List Contains
  • Page Object Model
  • TestNG Annotations
  • Python Function Quiz
  • Python String Quiz
  • Python OOP Test
  • Java Spring Test
  • Java Collection Quiz
  • JavaScript Skill Test
  • Selenium Skill Test
  • Selenium Python Quiz
  • Shell Scripting Test
  • Latest Python Q&A
  • CSharp Coding Q&A
  • SQL Query Question
  • Top Selenium Q&A
  • Top QA Questions
  • Latest Testing Q&A
  • REST API Questions
  • Linux Interview Q&A
  • Shell Script Questions
© 2024 TechBeamers. All Rights Reserved.
Reading: Understand C Datatypes
Font ResizerAa
TechBeamersTechBeamers
Font ResizerAa
  • Python
  • SQL
  • C
  • Java
  • Testing
  • Selenium
  • Agile Concepts Simplified
  • Linux
  • MySQL
  • Python Quizzes
  • Java Quiz
  • Testing Quiz
  • Shell Script Quiz
  • WebDev Interview
  • Python Basic
  • Python Examples
  • Python Advanced
  • Python OOP
  • Python Selenium
  • General Tech
Search
  • Programming Tutorials
    • Python Tutorial
    • Python Examples
    • Java Tutorial
    • C Tutorial
    • MySQL Tutorial
    • Selenium Tutorial
    • Testing Tutorial
  • Top Interview Q&A
    • SQL Interview
    • Web Dev Interview
  • Best Coding Quiz
    • Python Quizzes
    • Java Quiz
    • Testing Quiz
    • ShellScript Quiz
Follow US
© 2024 TechBeamers. All Rights Reserved.
C Tutorials

Understand C Datatypes

Last updated: Sep 29, 2023 2:13 pm
By Meenakshi Agarwal
Share
8 Min Read
C Datatypes Range and Sizes
C Datatypes Range and Sizes
SHARE

In this C programming class, we’ll cover C datatypes, their purpose, and their limits. We’ll enhance understanding through the use of flowcharts and code examples for better explanations.

Contents
IntUnsigned intLongUnsigned longFloatDoubleCharUnsigned charShortUnsigned shortArrayPointersEnumStructure (struct)UnionFlowchart:Algorithm:Code:

The data types are the core building blocks in C. Hence, please read with full focus and concentration.

Let’s understand C Datatypes from scratch.

What are Data Types in C Programming?

In C programming, data types are exactly what their name suggests. They represent the kind of data that can be stored. They are used to declare functions and variables in a program.

There are three main categories of data types: Basic/Primitive, Derived, and User-Defined.

This diagram would help you.

C Datatypes to Use in Programs
C Data Types to Use in Programs

Now, we will see what each of them means individually.

Int

It is used to store the integer data type.

The regular integer that we use has a size of 2 bytes (16 bits) on a 16-bit machine. However, most modern systems have 32 or 64-bit configurations. The size of an integer in such an environment is 4 bytes with a starting value of -2,147,483,648 and an ending value of 2,147,483,647. Any operations involving a number out of this range will return either garbage or an error.

Note: Garbage value is nothing but waste or unused data in a program’s memory. It could also be related to variables that are no longer in use. So, it is always best to initialize to avoid any undefined behavior.

Unsigned int

An integer could also be of an unsigned type. Such a type (unsigned int) on 32-bit will have a range from 0 to 4,294,967,295 and 0 to 65535 on a 16-bit system.

Long

It also stores the integer data with a higher range. The long type is 4 bytes on 32-bit systems and 8 bytes in 64-bit setups.

The 32-bit long range is the same as an integer while on 64-bit, it can hold a minimum of -9,223,372,036,854,775,808 and goes up to 9,223,372,036,854,775,807.

Unsigned long

In some cases, we require only positive numeric values; then it’s better to use the unsigned type. It not only makes sure that you get one but also enhances the range.

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

Float

This data type is also numeric but allows numbers with decimal places. It has a size of 4 bytes and has a range of 3.4E-38 to 3.4E+38.

The float type has a precision of up to 7 digits.

Double

It is the same as float but with a higher precision range that is 8 bytes which gives it the ability to store more numerals after the decimal places, double to be exact.

It has a length of 8 bytes and a range of 1.7E +/- 308. The double data type has a precision of up to 15 digits.

Char

Char data type by default allows a single character such as a letter from the alphabet. It has the size of just 1 byte with a range of -128 to 127 or 0 to 255.

However, with an array [] suffix, it can hold string values, a combination of alphanumeric characters.

Unsigned char

Also, there is an unsigned char type that is similar but doesn’t allow the (-ve) values. It has the same size of 1 byte with a range of 0 to 255.

Short

The length of the short type is two bytes. It allows the range of values equal to 2 to the power 16, i.e., up to 16 bits. Since it is a signed one, hence, contains both the positive and negative values.

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

Unsigned short

The unsigned short type contains only +ve numbers and also has a size of 2 bytes. It can store a minimum value of 0 and goes up to a maximum of 65 535.

Array

A C array is a contiguous sequence of elements of a similar data type. It is primarily to create a collection of the primitives like numbers, chars, struct, and unions.

We have a dedicated chapter for the Arrays which you can go through later.

Pointers

Pointers are used to point and access the values stored at an address in the program’s dynamic memory known as the heap.

The pointer type variables get stored on the heap while the other types are on the stack.

Like an array can have multiple elements, the pointer too can hold several values depending upon the amount of memory it gets allocated.

This data type also has a chapter dedicated to it so we will see more of it later.

Enum

The enum is used to assign a name to a variable to a constant. We will also are this in further chapters.

Structure (struct)

The structure type is used to create a data type that can hold multiple data types in it.

Union

A union is a data type that has all values under it stored at a single address.

In the below C data types example, we’ll see the use of the two fundamental C datatypes.

Data Types Range and Sizes

We’ve captured all the fundamental C datatypes along with their size in bytes and the range of values in the below table.

C Datatypes Range and Sizes
C Data Types Range and Sizes

Sample Program: Print Quotient of Two Numbers

In this example, we will perform the arithmetic division operation on two integer numbers. After that, the same result will get assigned to two variables of the following types.

  • Integer
  • Float

Let’s first understand the flow of this program with the help of its flowchart.

Flowchart:

Get Quotient of Two Integers - Flowchart

Algorithm:

Step 1: Start.

Step 2: Initialize variables.

Step 3: Take input from the user.

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

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

Step 6: Stop.

Code:

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

void main()
{
    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);

    getch();
}

Note: float data type is declared in printf using %f just as the int is declared using %d.

The output should look something like this.

C Datatypes Program Output
C Datatypes Program Output

Note: If we use the double type, then it would also give the same output, but it would matter for programs where accuracy is needed.

We have just covered the basics here. You shall learn more about the C data types and their advanced usage in the next C programming tutorials.

You Might Also Like

C Programming Language “Struct”

20 C Programs for Beginners to Practice

Learn C Programming – How To Guide for Beginners

Python vs C++ – Is Python or C++ Better?

The Best Top-Down Approach Guide for You in C

Meenakshi Agarwal Avatar
By Meenakshi Agarwal
Follow:
Hi, I'm Meenakshi Agarwal. I have a Bachelor's degree in Computer Science and a Master's degree in Computer Applications. After spending over a decade in large MNCs, I gained extensive experience in programming, coding, software development, testing, and automation. Now, I share my knowledge through tutorials, quizzes, and interview questions on Python, Java, Selenium, SQL, and C# on my blog, TechBeamers.com.
Previous Article Understanding C Variables
Next Article What are different types of Operators in C Language? C Operators – Learn Step by Step

Popular Tutorials

SQL Interview Questions List
50 SQL Practice Questions for Good Results in Interview
SQL Interview Nov 01, 2016
Demo Websites You Need to Practice Selenium
7 Sites to Practice Selenium for Free in 2024
Selenium Tutorial Feb 08, 2016
SQL Exercises with Sample Table and Demo Data
SQL Exercises – Complex Queries
SQL Interview May 10, 2020
Java Coding Questions for Software Testers
15 Java Coding Questions for Testers
Selenium Tutorial Jun 17, 2016
30 Quick Python Programming Questions On List, Tuple & Dictionary
30 Python Programming Questions On List, Tuple, and Dictionary
Python Basic Python Tutorials Oct 07, 2016
//
Our tutorials are written by real people who’ve put in the time to research and test thoroughly. Whether you’re a beginner or a pro, our tutorials will guide you through everything you need to learn a programming language.

Top Coding Tips

  • PYTHON TIPS
  • PANDAS TIPSNew
  • DATA ANALYSIS TIPS
  • SELENIUM TIPS
  • C CODING TIPS
  • GDB DEBUG TIPS
  • SQL TIPS & TRICKS

Top Tutorials

  • PYTHON TUTORIAL FOR BEGINNERS
  • SELENIUM WEBDRIVER TUTORIAL
  • SELENIUM PYTHON TUTORIAL
  • SELENIUM DEMO WEBSITESHot
  • TESTNG TUTORIALS FOR BEGINNERS
  • PYTHON MULTITHREADING TUTORIAL
  • JAVA MULTITHREADING TUTORIAL

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Loading
TechBeamersTechBeamers
Follow US
© 2024 TechBeamers. All Rights Reserved.
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
  • Terms of Use
TechBeamers Newsletter - Subscribe for Latest Updates
Join Us!

Subscribe to our newsletter and never miss the latest tech tutorials, quizzes, and tips.

Loading
Zero spam, Unsubscribe at any time.
x