Data Types in C
In C programming,
Data types are declarations for variables.
Variables on the other hand are memory allocations in a programming language.
Example :
int age;
Here, age is a variable of int (integer) type.
The size of int is 4 bytes.
Basic Data types in C
Type Size (bytes) Format Specifier
int 2 %d , %i
char 1 %c
float 4 %f
double 8 %lf
short int 2 %hd
unsigned int 2 %u
long int 4 %ld , %li
Long long int Atleast 8 %lld, %lli
Basic Data types in C
Type Size (bytes) Format Specifier
Unsigned long int Atleast 4 %lu
Unsigned long long int Atleast 8 %llu
Signed char 1 %c
Unsigned char 1 %c
Long double Atleast 10 %Lf
1. int

Integers are whole numbers that can have both zero, positive and negative values but
no decimal values.
For example, 0, -5, 10.

The size of int is usually 4 bytes (32 bits).

We can use int for declaring an integer variable.
e.g. “ int id; ”

Here, id is a variable of type integer.
NB : You can declare multiple variables at once in C programming.
For example;
“ int id, age; ”
2. float and double

float and double are used to hold real numbers.
For example ;
float salary;
double price;
NB : In C, floating-point numbers can also be represented in exponential.
For example,
float normalizationFactor = 22.442e2;
 Question:
What's the difference between float and double?
 The size of float (single precision float data type) is 4 bytes.
 And the size of double (double precision float data type) is 8 bytes.
3. char

Keyword char is used for declaring character type
variables.
For example,
char test = 'h';

The size of the character variable is 1 byte.
4. void

void is an incomplete type.

It means "nothing" or "no type". You can think of void as
absent.

For example,
if a function is not returning anything, its return type
should be void.

Note that, you cannot create variables of void type.
5. short and long

If you need to use a large number, you can use a type specifier long.
Here's how:
long a;
long long b;
long double c;

Here variables a and b can store integer values. And, c can store a floating-point number.

If you are sure, only a small integer ([−32,767, +32,767] range) will be used, you can use
short.
Here’s how:
short d;
HOW TO CHECK THE SIZE OF A VARIABLE

You can always check the size of a variable using the sizeof() operator.
#include <stdio.h>
int main() {
short a;
long b;
long long c;
long double d;
printf("size of short = %d bytesn", sizeof(a));
printf("size of long = %d bytesn", sizeof(b));
printf("size of long long = %d bytesn", sizeof(c));
printf("size of long double= %d bytesn", sizeof(d));
return 0;
}
Resources for more Learning
Data Types in C Programming
DataTypes In C | What Are DataTypes In C and Their Types | C Programming for Be
ginners

Structured Programming with C - Data Types.ppt

  • 1.
    Data Types inC In C programming, Data types are declarations for variables. Variables on the other hand are memory allocations in a programming language. Example : int age; Here, age is a variable of int (integer) type. The size of int is 4 bytes.
  • 2.
    Basic Data typesin C Type Size (bytes) Format Specifier int 2 %d , %i char 1 %c float 4 %f double 8 %lf short int 2 %hd unsigned int 2 %u long int 4 %ld , %li Long long int Atleast 8 %lld, %lli
  • 3.
    Basic Data typesin C Type Size (bytes) Format Specifier Unsigned long int Atleast 4 %lu Unsigned long long int Atleast 8 %llu Signed char 1 %c Unsigned char 1 %c Long double Atleast 10 %Lf
  • 4.
    1. int  Integers arewhole numbers that can have both zero, positive and negative values but no decimal values. For example, 0, -5, 10.  The size of int is usually 4 bytes (32 bits).  We can use int for declaring an integer variable. e.g. “ int id; ”  Here, id is a variable of type integer. NB : You can declare multiple variables at once in C programming. For example; “ int id, age; ”
  • 5.
    2. float anddouble  float and double are used to hold real numbers. For example ; float salary; double price; NB : In C, floating-point numbers can also be represented in exponential. For example, float normalizationFactor = 22.442e2;  Question: What's the difference between float and double?  The size of float (single precision float data type) is 4 bytes.  And the size of double (double precision float data type) is 8 bytes.
  • 6.
    3. char  Keyword charis used for declaring character type variables. For example, char test = 'h';  The size of the character variable is 1 byte.
  • 7.
    4. void  void isan incomplete type.  It means "nothing" or "no type". You can think of void as absent.  For example, if a function is not returning anything, its return type should be void.  Note that, you cannot create variables of void type.
  • 8.
    5. short andlong  If you need to use a large number, you can use a type specifier long. Here's how: long a; long long b; long double c;  Here variables a and b can store integer values. And, c can store a floating-point number.  If you are sure, only a small integer ([−32,767, +32,767] range) will be used, you can use short. Here’s how: short d;
  • 9.
    HOW TO CHECKTHE SIZE OF A VARIABLE  You can always check the size of a variable using the sizeof() operator. #include <stdio.h> int main() { short a; long b; long long c; long double d; printf("size of short = %d bytesn", sizeof(a)); printf("size of long = %d bytesn", sizeof(b)); printf("size of long long = %d bytesn", sizeof(c)); printf("size of long double= %d bytesn", sizeof(d)); return 0; }
  • 10.
    Resources for moreLearning Data Types in C Programming DataTypes In C | What Are DataTypes In C and Their Types | C Programming for Be ginners