C - Data Types
C - Data Types
TUTORIAL
C - Data types
Chapter
1. C - Data types
Topics
int: These variables depend on the word size of the computer. So,
generally, they take 16-bits on old 16-bit computers, whereas on
modern 32-bit and 64-bit computers they consume 32-bits of
memory. you cannot make assumptions about the size of an integer
if you want your programs to be portable to the widest range of
environments.
https://codequotient.com/tutorialpdf/5a1d94b752795c1b16c0abea 1/4
8/27/23, 6:28 PM PDF | CodeQuotient
If a variable takes 8-bits in memory, it can take all bits from 0000
0000 to all bits 1111 1111, making total of 256 combinations. Which
results in range of this variable. Now either this range can hold half
negative and half positive numbers or it can hold all positive
numbers. So an 8-bit signed variable may hold -128 to 127 values.
Which is -2^7 to 2^7 -1 values. So in general if a variable takes n-bits
in memory, then its signed representsation will take -2^(n-1) to
+2^(n-1)-1 values, and its unsigned representation may take 0 to
2^(n)-1 values.
1 #include <stdio.h> C
2
3 int main()
4 {
5 char c; // c is a character variable of 8
bits. May hold value from -128 to 127.
6 signed char c1; // c is a character variable
of 8 bits. May hold value from -128 to 127.
7 unsigned char c2; // c is a character variable of
8 bits. May hold value from 0 to 255.
8 int i; // i is a integer variable of 16/32
bits.
9 short int j; // i will be short integer of 16-
bits.
10 long int li; // li is a long int variable,
taking 32-bits.
11 float f; // f is single-precision floating
number taking 32-bits
https://codequotient.com/tutorialpdf/5a1d94b752795c1b16c0abea 2/4
8/27/23, 6:28 PM PDF | CodeQuotient
Type Qualifiers
volatile tells the compiler that the value of a variable may change
outside of the program also, due to some external activity.
https://codequotient.com/tutorialpdf/5a1d94b752795c1b16c0abea 3/4
8/27/23, 6:28 PM PDF | CodeQuotient
tient.com
Tutorial by codequotient.com | All rights reserved, CodeQuotient 2023
https://codequotient.com/tutorialpdf/5a1d94b752795c1b16c0abea 4/4