Size of Data Types in C | GATE Notes (2023)

Data types are one of the most crucial features in the C programming language. We use the data types with functions and variables for defining what kind of data it typically holds. This data can be some type of character or value. There can also be various sets of characters or sets of values. The C language offers a very wide range of all the data types, and each of these may contain a unique data type with some certain range that is predefined.

Ultimate Guide to Kickstart your GATE Exam Preparation
Download the e-book now

In this article, we will take a closer look at the Size of Data Types in C according to the GATE Syllabus for CSE (Computer Science Engineering). Read ahead to know more.

Table of Contents

  • Types Of Data Types In C
  • Primary Data Types
    • Size Of Primary Data Types
    • Char Size
    • Short Integer Size
    • Long Integer Size
      • What Differentiates The Range For Unsigned And Signed Types?
      • The 1’S Complement
      • The 2’S Complement
  • The Floating Point Data Types
    • The Normalised Form
    • The De-Normalised Form
      • Summary
  • The Derived Data Types
  • Practice Problems On Size Of Data Types In C
  • FAQs

Types of Data Types in C

The C programming language has two basic data types:

  • Primary
  • Derived

Primary Data Types

The primary data types are basically standard data types that the C language defines. The language defines four of the basic data types in programming. These are:

char – these are single-byte in nature. The char data type can hold a single character in a local character set.

float – these are single-precision types of floating-point.

int – these are integers. They typically reflect the integer’s natural size on a host machine.

double – these are double-precision types of floating-point.

Apart from this, one can also apply various numbers of qualifiers to the basic data types. The long and short qualifiers applied to integers would turn out to be:

long int counter;

short int sh;

*Note that we can omit the word int in such types of declarations.

Size of Primary Data Types

Here is a list of all the primary data types:

TypeRangeSize (in bytes)
unsigned char0 to 2551
signed char or char-128 to +1271
unsigned int0 to 655352
signed int or int-32,768 to +327672
unsigned short int0 to 655352
signed short int or short int-32,768 to +327672
unsigned long int0 to +4,294,967,2954
signed long int or long int-2,147,483,648 to +2,147,483,6474
long double3.4E-4932 to 1.1E+493210
double1.7E-308 to 1.7E+3088
float3.4E-38 to 3.4E+384

The data type size and range depend a lot on the compiler. However, the code that the compiler compiles is targeted for some specific types of Microcontrollers or Microprocessors. One single compiler can provide support for multiple targets or processors. The compiler then defines the size for the available data types on the basis of the selected target. In simpler words, the size of any data type is directly dependent on the compiler along with the target processor (for which the code generation occurs using the compiler).

In the table mentioned above, we have assumed a 16-bit compiler. It means that the code generation of the compiler will be for a 16-bit target processor. The integer is, normally, the natural size for any processor or machine. In the table mentioned above, the integer is 16-bit or 2 bytes wide. Thus, the compiler is also 16-bit or 2 bytes wide. If the compiler was 32-bit wide, the int type size would have been about 32-bits or 4 bytes. However, this might not be the case every single time. It is also possible that the integer size is 32-bits or 4 bytes for a 64-bits processor. It entirely depends on the type of compiler.

Let us take a look at an example of an integer data type:

int temp; // the ‘temp’ variable is capable of holding the integer values

(both negative or positive)

temp = 50;

temp = -50;

signed int temp; // the ‘temp’ variable is capable of holding the integer values

(both negative or positive)

temp = 987654;

temp = -987654;

unsigned int temp; // the ‘temp’ variable is capable of holding the integer values

(only positive)

temp = 87654;

temp = -8; // The given assignment is invalid

Char Size

The size of both unsigned and signed char is 1 byte always, irrespective of what compiler we use. Here, a signed character is capable of holding negative values. Thus, the defined range here is -128 to +127. But the unsigned character is only capable of holding the positive values. Thus, the range for such characters is from 0 to 255. These character data types are capable of storing the ASCII characters or the numbers that are equivalent to the ASCII characters.

Short Integer Size

The size of both unsigned and signed integers is about 2 bytes in a majority of the compilers.

Long Integer Size

The size of both unsigned and signed long integers depends on the type of compiler that we use. The size is typically about 32-bits or 4 bytes on a 16/ 32-bit compiler. Yet, it varies depending on what compiler we are using.

There is no specification of the data types sizes according to the C standard, except the character. According to the definition by C:

Every compiler can choose an appropriate size for hardware of its own. It is only subjected to a single restriction that the longs are 32 bits at least, ints and shorts are 16 bits at least, the short is not longer than the int, and the int is not longer than the long.

What differentiates the range for unsigned and signed types?

Although the size of any unsigned as well as the signed data type is all the same, they both possess different ranges of values to be stored in any variable. Why? It is because the representation of the signed numbers is in 2’s complement form in any processor or machine. For instance, the representation of the number -23 in the form of 2’s complement would be:

(Decimal) 23 <-> (Binary) 10111

The 1’s complement

The 1’s complement of 10111 will be – 1111111111111111111111111111111111111111111111111111111111101000

Here, the total number of 1s that are added before the actual number depends a lot on the size of the machine or that of the target processor. Since the machine we are dealing with here is a 64-bit machine, we have added these many 1s, so that the final number also becomes a 64-bit number.

In simpler words, the 1’s complement is basically an inverted version of the actual number. The 0s get converted to 1s and the 1s get converted to 0s.

The 2’s complement

The 2’s complement is basically 1’s complement + 1, i.e.,

1111111111111111111111111111111111111111111111111111111111101000 + 1:

1111111111111111111111111111111111111111111111111111111111101001 <-> (decimal) -23

Some calculations on the computer would help you verify this result here.

Let us take a look at an example of a signed character that is capable of storing numbers that fall between -128 to +127. Now, we all know that both unsigned and signed char are capable of storing just 8-bits of data in them.

So, if we assume that we are trying to store a number, -190, in an 8-bits wide variable character, then the processor would handle the number as follows:

(Decimal) 190 <-> (Binary) 10111110 : 8-bits

1’s complement of the value 190: (Binary) 01000001 : 8-bits

2’s complement of the value 190: (Binary) 01000010 : 8-bits

(Binary) 01000010 <-> (Decimal) 66

The interpretation of the character numbers by the computer would be as follows:

(1) MSB bit: The sign of the number [0: Positive, 1: Negative], 7-0 Bits: 1000010: [66] Actual data

It means that whenever we try to store a number that is greater than the defined range, the number will ultimately get rounded down. Thus, we got the result of 256-190 to be 66. Here, 256 is basically the maximum value that an unsigned character number can keep stored.

Now, let us take a look at another example of how we can store the number -126 in a variable of char data type.

(Decimal) 126 <-> (Binary) 01111110

1’s complement of 126: (Binary) 10000001 : 8-bits

2’s complement of 126: (Binary) 10000010 : 8-bits

(Binary) 10000010 <-> (Decimal) -126

If you want to verify the obtained results, you can perform reverse calculations. Here, the number is negative since the MSB is 1. Also, 0000010 are the other 7 bits. Thus, the number’s 2’s complement would be: ~0000010 = 1111101 = (Decimal) 126

If we combine the number and the sign here, we will obtain the result to be: (Decimal) -126

The very same concept goes well with both unsigned as well as signed integer data types.

In a brief conclusion, both unsigned and signed numbers have the very same definition for data size in C. However, the representation of the signed numbers is in the 2’s complement form, and the binary number’s most significant bit represents that number’s sign. Since binary 1 (extra 1 bit) is there to identify this given number as negative, the overall range of the signed numbers is much less than that of the unsigned numbers.

Your processor handles the negative numbers, and thus, you don’t have to take care of them separately. Just make sure that you assign a valid number to the signed variable that falls in the defined range. In case you fail to do this, the assigned number will ultimately get truncated.

The Floating Point Data Types

The C language specifies two of the primary data types for storing the fractional numbers or the floating-point. These are double or float. One can easily apply the long qualifiers on the double. Thus, we get another type, which is the long double.

In a computer system, the IEEE-754 format represents the floating-point numbers. A majority of modern processors and processors adopt this format. It has two major representations:

1. 32-bit single precision

2. 64-bit double precision

The representation of the floating numbers has further classifications. These are:

1. The Normalised Form

We will take a look at an example to understand this better.

Assume that the 32-bit type of pattern is

1 1000 0001 011 0000 0000 0000 0000 0000, where:

F = 011 0000 0000 0000 0000 0000

E = 1000 0001

S = 1

In a normalised form, the mantissa or the actual fraction is normalised using an implicit that leads 1, which is in the form of 1.F. For instance, in the example mentioned here, the actual fraction would be 1.011 0000 0000 0000 0000 0000 = 1 + 1×2^-2 + 1×2^-3 = 1.375D.

Here, the sign bit basically represents the number’s sign, where S=1 is a negative number and S=0 is a positive number. In the example mentioned above, the S=1. Thus, the number is negative. It means that the number would be -1.375D.

The actual exponent in the normalised form would be E-127 (it is the so-called bias-127 or excess-127). It is because a person needs to represent both negative and positive exponents. In the case of an 8-bit E that ranges from 0 to 255, the actual exponent of the numbers -127 to 128 could be provided by the excess -127 scheme. For instance, in the mentioned example, E-127=129-127=2D.

2. The De-Normalised Form

The normalised form has some serious problems. For instance, it uses an implicit that leads 1 for a fraction. Thus, the normalised form cannot represent zero as a number that would start with 1. The de-normalised form is basically devised for representing the number zero as well as the other numbers. These numbers are in a de-normalised form for the E=0. An implicit that leads 0 and not 1 would be used for a fraction. The actual exponent here is always -126. Thus, we can represent the number 0 using an F=0 and an E=0, because 0.0×2^-126 = 0.

A person can easily represent very small negative and positive numbers in a de-normalised form using an E=0. For instance, if F=011 0000 0000 0000 0000 0000, E=0, and S=1, the actual fraction would be 0.011 = 1×2^-2+1×2^-3 = 0.375D. Now since S=1, the given number is actually negative. Now with E=0, -126 would be the actual exponent. Thus, the number here is -0.375 × 2^ – 126 = -4.4×10^ – 39. Now, this is an extremely small number that is negative (very close to the number 0).

Summary:

The calculation of the value N would be:

(a) For 1 ≤ E ≤ 254, N = (-1)^S × 1.F × 2^(E-127).

The numbers here are in a normalised form. The sign of the number here is represented by the sign-bit. The implicit that leads 1 normalises the fractional part, that is 1.F. The exponent here is in excess (or bias) of 127 for representing both negative and positive exponents. The overall range of the exponents here would be -126 to +127.

(b) In the case of E = 0, N = (-1)^S × 0.F × 2^(-126).

All of these numbers are in the de-normalised form. Thus, the exponent of the value 2^-126 would then evaluate as a number that is very small. We need to represent the denormalised form using E=0 and F=0. These can also represent extremely negative and positive numbers that are close to the value of zero.

(c) In the case of E = 255, some special values would be represented, for instance, NaN (it refers to not a number) and ±INF (the negative and positive infinity).

The Derived Data Types

These are also known as user-defined types. This data type is derived out of the primary data type, thus known as the derived data types. But these are capable of storing a set of various values instead of storing one single value. Unions, structures, arrays, and enum are some of the most common ones in the C language.

Practice Problems on Size of Data Types in C

1. The size of char is 1 byte when the char is:

A. Signed

B. Unsigned

C. Both

D. None. It is more than 1 byte.

Answer – C. Both

2. The int data type reflects the natural size of a _________ on a _____________.

A. integer, program

B. integer, host machine

C. floating-point, host machine

D. floating-point, program

Answer – B. integer, host machine

3. The range and size of a data type range between various:

A. Compilers

B. Operating Systems

C. Both

D. None

Answer – C. Both

FAQs

Q1

What differentiates the range for unsigned and signed types?

Although the size of any unsigned as well as the signed data type is all the same, they both possess different ranges of values to be stored in any variable. Why? It is because the representation of the signed numbers is in 2’s complement form in any processor or machine. For instance, the representation of the number -23 in the form of 2’s complement would be:
(Decimal) 23 <-> (Binary) 10111

Q2

Why do we use the floating data types?

The C language specifies two of the primary data types for storing the fractional numbers or the floating-point. These are double or float. One can easily apply the long qualifiers on the double. Thus, we get another type, which is the long double.
In a computer system, the IEEE-754 format represents the floating-point numbers. A majority of modern processors and processors adopt this format. It has two major representations:
1. 32-bit single precision
2. 64-bit double precision

Keep learning and stay tuned to get the latest updates onGATE Examalong withGATE Eligibility Criteria,GATE 2023,GATE Admit Card,GATE Syllabus for CSE (Computer Science Engineering),GATE CSE Notes,GATE CSE Question Paper, and more.

Also Explore,

  • Constants in C
  • Double Data Type in C
  • Enumerated Data Type in C
  • Operator Precedence and Associativity in C

FAQs

Size of Data Types in C | GATE Notes? ›

Types of Data Types in C

Floating-point, integer, double, character. Union, structure, array, etc. The basic data types are also known as the primary data types in C programming.

What are the data types in C notes? ›

Types of Data Types in C

Floating-point, integer, double, character. Union, structure, array, etc. The basic data types are also known as the primary data types in C programming.

What are the 32 data types in C? ›

int , long , ptr , and off_t are all 32 bits (4 bytes) in size. int is 32 bits in size. long , ptr , and off_t are all 64 bits (8 bytes) in size. The 32-bit data model for z/OS® XL C/C++ compilers is ILP32 plus long long.

What is the size of datatype? ›

Basic Data Types
Data TypesMemory SizeRange
signed char1 byte−128 to 127
unsigned char1 byte0 to 255
short2 byte−32,768 to 32,767
signed short2 byte−32,768 to 32,767
14 more rows

What is the size of data types in embedded C? ›

Embedded C supports three different data types for integers: int, short, and long. On 8-bit architectures, the default size of int values is typically set to 16 bits but Embedded C allows for int sizes to be switched between 8 and 16 bits to reduce memory consumption.

What are the 5 different data types? ›

The data types to know are:
  • String (or str or text). Used for a combination of any characters that appear on a keyboard, such as letters, numbers and symbols.
  • Character (or char). Used for single letters.
  • Integer (or int). Used for whole numbers.
  • Float (or Real). ...
  • Boolean (or bool).

What is the smallest data type in C? ›

Generally, the smallest addressable chunk of data in C is a byte.

What is the size of data types in C in 32-bit? ›

Table 2-2 D Integer Data Types
Type Name32–bit Size64–bit Size
char1 byte1 byte
short2 bytes2 bytes
int4 bytes4 bytes
long4 bytes8 bytes
1 more row

What is 64-bit data type in C? ›

A double data type number uses 64 bits giving a precision of 14 digits. These are known as double precision numbers.

What is the size of an int in C? ›

The size of int is usually 4 bytes (32 bits). And, it can take 232 distinct states from -2147483648 to 2147483647 .

How to find the size of a variable in C? ›

The sizeof() operator is used to find out the size of the variable, pointer, array, or expression passed to it. It is generally useful in finding out the amount of memory space in bytes needed to store a variable, pointer, array, or the result of an expression.

What is the smallest size data type? ›

Boolean data is the simplest possible form of data. It is either True or False, a 1 or a 0. In Alteryx a Boolean record takes up one byte and is denoted by Bool in field type menus.

What are the largest data types in C? ›

Limits on Integer Constants
ConstantMeaningValue
INT_MAXMaximum value for a variable of type int .2147483647
UINT_MAXMaximum value for a variable of type unsigned int .4294967295 (0xffffffff)
LONG_MINMinimum value for a variable of type long .-2147483647 - 1
LONG_MAXMaximum value for a variable of type long .2147483647
15 more rows
Aug 2, 2021

What is the size of float in C? ›

4 bytes

Which is the huge data type in C? ›

The long data type stores integers like int , but gives a wider range of values at the cost of taking more memory. Long stores at least 32 bits, giving it a range of -2,147,483,648 to 2,147,483,647.

What are the 7 types of data? ›

And there you have the 7 Data Types.
  • Useless.
  • Nominal.
  • Binary.
  • Ordinal.
  • Count.
  • Time.
  • Interval.
Aug 29, 2018

What are the 4 main data types? ›

4 Types of Data: Nominal, Ordinal, Discrete, Continuous.

What is the size of C structure? ›

The size of the entire structure is 8 bytes.

What is abstract data type in C? ›

An abstract data type in data structure is a kind of a data type whose behavior is defined with the help of some attributes and some functions. An abstract data type in data structure can be that of a list data structure, stack data structure and a queue data structure.

What are the primitive data types in C? ›

There are eight primitive data types: Boolean, byte, character, short, int, long, float, and double.

What is byte type in C? ›

A byte is typically 8 bits. C character data type requires one byte of storage. A file is a sequence of bytes. A size of the file is the number of bytes within the file.

What is the size of long int? ›

64-bit UNIX applications
NameLength
int4 bytes
long8 bytes
float4 bytes
double8 bytes
9 more rows
Apr 30, 2018

How many bits is a long in C? ›

1. Integer types
NameTypical sizeSigned by default?
short16 bitsYes
int32 bitsYes
long32 bitsYes
long long64 bitsYes
1 more row

What is the size of string data type in C? ›

The string length in C is equal to the count of all the characters in it (except the null character "\0"). For Example, the string "gfddf" has a length of 5 and the string "4343" has a length of 4.

What are 8-bit data types C? ›

In C, the unsigned 8-bit integer type is called uint8_t . It is defined in the header stdint. h . Its width is guaranteed to be exactly 8 bits; thus, its size is 1 byte.

What is 32-bit and 64 bit in C? ›

More specifically, it addresses a maximum of 4,294,967,296 bytes (4 GB) of RAM. The 64 bit OS, on the other hand, can handle more data than the 32 bit OS. It means that it can address a total of 264 memory addresses, which is 18-Quintillion GB of RAM.

What data type is 16 bit in C? ›

16-bit signed integer type is used to store negativ or pozitiv whole number. 16-bit integer and his value range: from -32768 to 32767.

What is 16 bit datatype in C? ›

Main types
TypeMinimum size (bits)Range
unsigned short unsigned short int160 / USHRT_MAX
int signed signed int16INT_MIN / INT_MAX
unsigned unsigned int160 / UINT_MAX
long long int signed long signed long int32LONG_MIN / LONG_MAX
10 more rows

Is C 32-bit? ›

Pointers. The ARMv7-M architecture used in mbed microcontrollers is a 32-bit architecture, so standard C pointers are 32-bits.

What is the size of char in C? ›

Integer Types
TypeStorage sizeValue range
char1 byte-128 to 127 or 0 to 255
unsigned char1 byte0 to 255
signed char1 byte-128 to 127
int2 or 4 bytes-32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
5 more rows

What is the size of int vs char in C? ›

Size of an int is 4 bytes on most architectures, while the size of a char is 1 byte.

What is the size of char * in C? ›

In C the type of character literal is integer (int). So in C the sizeof('a') is 4 for 32bit architecture, and CHAR_BIT is 8. But the sizeof(char) is one byte for both C and C++.

Is there a size function in C? ›

We generally use the sizeof() operator in the C language so that we can determine the sizes of the data types or the expressions that are specified in the storage units of char-size. The sizeof() operator consists of just one operand that can either be a cast data type or an expression.

What is the size function in C? ›

The sizeof() function in C is a built-in function that is used to calculate the size (in bytes)that a data type occupies in ​the computer's memory. A computer's memory is a collection of byte-addressable chunks.

What data type is bigger than int? ›

If you need to hold an integer larger than the Integer data type can hold, you can use the Long data type instead. Long variables can hold numbers from -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807. Operations with Long are slightly slower than with Integer .

Which data type is smaller than int? ›

What Is Byte? Byte data type is an 8-bit signed two's complement integer. This sort of data type is applied for saving memory in large arrays, primarily in the place of integers. Because a byte is four times smaller than an int.

What is tiny data type? ›

SQL SmallInt. The TINYINT data type is an integer value from 0 to 255. TINYINT is the smallest integer data type and only uses 1 byte of storage. An example usage of TINYINT is a person's age since no person reaches the age of 255.

How many bytes is a short in C? ›

The short data type takes 2 bytes of storage space; int takes 2 or 4 bytes, and long takes 8 bytes in 64-bit and 4 bytes in the 32-bit operating system.

What is size modifiers for data types in C? ›

These are keywords in C to modify the default properties of int and char data types. There are 4 modifiers in C as follows. short It limits user to store small integer values from -32768 to 32767.

What is float data type in C? ›

Float is a datatype which is used to represent the floating point numbers. It is a 32-bit IEEE 754 single precision floating point number ( 1-bit for the sign, 8-bit for exponent, 23*-bit for the value. It has 6 decimal digits of precision.

What is the size of long in C? ›

The C and C++ specifications only state that long must be greater than or equal to 32 bits. int can be smaller, but on many platforms, in C and C++, long and int are both 32 bits.

Is float bigger than double in C? ›

float and double both have varying capacities when it comes to the number of decimal digits they can hold. float can hold up to 7 decimal digits accurately while double can hold up to 15.

What is the size of int or float? ›

Apparently, float and int take up the same amount of bytes, 4. However, according to this page, has its limit on 2,147,483,647, while float supports numbers as high as 3.4E+38.

Which data type has the highest storage? ›

Memo is the data type that has the largest storage capacity. It provides storage for variable length and arbitrary format data.

Which data type has the largest range? ›

Explanation: Longtext has largest range.

What's the biggest data type? ›

Integer Data TypeLowest Possible ValueHighest Possible Value
tinyint (integer1)-128+127
smallint (integer2)-32,768+32,767
integer (integer4)-2,147,483,648+2,147,483,647
bigint (integer8)-9,223,372,036,854,775,808+9,223,372,036,854,775,807
Jan 30, 2023

What are data types and variables in C? ›

In C, there are different types of variables (defined with different keywords), for example: int - stores integers (whole numbers), without decimals, such as 123 or -123. float - stores floating point numbers, with decimals, such as 19.99 or -19.99. char - stores single characters, such as 'a' or 'B' .

What is data types and explain its types? ›

A data type is a classification of data which tells the compiler or interpreter how the programmer intends to use the data. Most programming languages support various types of data, including integer, real, character or string, and Boolean.

What are identifiers in C? ›

"Identifiers" or "symbols" are the names you supply for variables, types, functions, and labels in your program. Identifier names must differ in spelling and case from any keywords. You can't use keywords (either C or Microsoft) as identifiers; they're reserved for special use.

How many bytes is an int in C? ›

Basic Data Types
TypeStorage SizeValue Range
Int (or signed int)2 bytes-32,768 to 32,767
unsigned int2 bytes0 to 65,535
Short int(or signed short int)2 bytes-32,768 to 32,767
Long(or singed short int)4 bytes-2,147,483,648 to 2,147,483,647
6 more rows
May 24, 2023

Which of the following data types is the largest? ›

Memo is the data type that has the largest storage capacity. It provides storage for variable length and arbitrary format data. There are two variations to Memo datatype: CLOB and BLOB data types.

What is an array in C? ›

Array in C can be defined as a method of clubbing multiple entities of similar type into a larger group. These entities or elements can be of int, float, char, or double data type or can be of user-defined data types too like structures.

What are the 5 identifiers? ›

Explain all C++ Identifiers
  • 1.Constants.
  • 2.Variables.
  • 3.Functions.
  • 4.Labels.
  • 5.Defined Data Types.

What is recursion in C? ›

Recursion is the technique of making a function call itself. This technique provides a way to break complicated problems down into simple problems which are easier to solve. Recursion may be a bit difficult to understand. The best way to figure out how it works is to experiment with it.

What is the size of a char in C? ›

Integer Types
TypeStorage sizeValue range
char1 byte-128 to 127 or 0 to 255
unsigned char1 byte0 to 255
signed char1 byte-128 to 127
int2 or 4 bytes-32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
5 more rows

References

Top Articles
Latest Posts
Article information

Author: Msgr. Benton Quitzon

Last Updated: 16/11/2023

Views: 6402

Rating: 4.2 / 5 (43 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Msgr. Benton Quitzon

Birthday: 2001-08-13

Address: 96487 Kris Cliff, Teresiafurt, WI 95201

Phone: +9418513585781

Job: Senior Designer

Hobby: Calligraphy, Rowing, Vacation, Geocaching, Web surfing, Electronics, Electronics

Introduction: My name is Msgr. Benton Quitzon, I am a comfortable, charming, thankful, happy, adventurous, handsome, precious person who loves writing and wants to share my knowledge and understanding with you.