Data Types in C | Programming Concept | 4 Types of data types

In this article, we will learn about the very important concept of any programming language which is data types. Without the data types, you can not write a program. So let’s start and dive deeper into data types in C

Data Types:- As the name indicates, data type i.e., types of data which a variable can hold. So basically, data types specify the type of data which can be entered/assigned in the particular variables/identifiers.

One may ask why do we need data types and what’s its purpose is?

As you already knew that world is full of so many intelligent people. While surfing the Internet or filling any form online/offline if one is asked to enter a mobile number they will try to enter some symbols, alphabets etc. to prove that they are intelligent.

So to avoid these types of errors caused by intelligent people which can harm our data integrity we have to use data types in C or in any programming language with proper and strict validations.

Data types in C

data types in c

Technically there are 4 types of data types in C

  • Primary/Basic/Fundamental Data Types
  • Derived Data Type
  • Enumuration Data Type
  • Void Data Type

Primary Data Types

primary data type
  • Primary data type is also known as Basic or Fundamenta data type.
  • These are also called arithmetic data type.
  • Categoriesed into 4 categories: (a) integer(int) (b) floating-point(float) (c) character (char)

Integer Type

  • Used for whole numbers.
  • eg: 23, 59, -78, -13 etc
  • Refer to the following table for the detail specifications
TypeSize(bytes)Range
Int (signed)2-32,768 to 32767
unsigned int20 to 65535
short int (signed)1-128 to 127
unsigned short int10 to 255
long int (signed)4-2,147,483,648 to 2,147,483,647
unsigned long int40 to 4,294,967,295

Floating Type

  • Used for real numbers.
  • eg: 23.5, 59.5, -78.0, -13.0 etc
  • Refer to the following table for the detail specifications
TypeSize(bytes)Range
Float43.4E-38 to 3.4E+38
double81.7E-308 to 1.7E+308
long double103.4E-4932 to 1.1E+4932

Character Type

  • Used for character
  • eg: ‘a’, ‘A’, ‘5’, ‘-8’ etc
  • Refer to the following table for the detail specifications

TypeSize(bytes)Range
char or signed char1-128 to 127
unsigned char10 to 255

Void Type

  • Void means empty, nothing.
  • Used with the function which return no value means return nothing on execution of it’s block.

Derived Data Type

  • Derived data types are used to derive a new user define data type as per the requirement of the programmer to accomplish the task at hand.
  • Pointer, Array, Structure, Union and Functions are the examples.
  • We will cover these topic in our upcoming articles.

Enumerated Data Type

  • Enumuration data type is also a user defined data type.
  • Used to assign names to integral constants.
  • Keyword enum is used to declare new enumuration data types in C.
  • Can be de defined in 2 ways
enum week{Mon, Tue, Wed};
enum week day;

or

enum week{Mon, Tue, Wed}day;

Variables in C

  • Variables are like containers which contain values depending on theeir data types.
  • Variables definitions tell the compiler where and how much storage is to be created.
  • Syntax for variable declaration
    • return_type variable_name(identifiers)
    • Eg:-
      • int i, j, k;
      • char ch;
      • float f;
  • syntax for variable declaration and Initialization
    • return_type variable=value;
    • Eg
      • int i=5, j=9, k=15;
      • char ch=’a’
      • float f=5.2 etc
  • Lvalues and Rvalues in C
    • Lvalues:- Repesent memory location and may appear either left or right side of the expressions. Eg- variables are lvalues which may appear either side of the expression.
    • Rvalues:- Repesent data value which is stored at a particular memory location and always must be appear at only right side of the expression. Eg: numeric literals or numbers are rvalues which always appears at the right side of the expression.

8 thoughts on “Data Types in C | Programming Concept | 4 Types of data types”

Leave a Comment

Ads Blocker Image Powered by Code Help Pro
Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Please Reload After Disabling Ad\'s