Fundamental Data Types in C

Unit 1

Chapter 1: Computer Basic*
*CS101 Computer Basic is a small separate course prerequisite for KCS101/KCS201 Programming for Problem Solving – Using C

Chapter 2: Terminology

Chapter 3: Idea of Algorithm

Chapter 4: Programming Basics

Unit 2

Chapter 5: Arithmetic Expressions and Precedence

Chapter 6: Conditional Branching

Unit 3

Chapter 7: Iteration and Loops

Chapter 8: Functions

Unit 4

Chapter 9: Arrays, Structure, Union, and Enumeration

Chapter 10: Basic Algorithms and their Complexity Coexistence

Unit 5

Chapter 11: Pointers

Chapter 12: File Handling

Chapter 13: Macros & Command-Line Arguments


KCS151/KCS251 PPS Lab Exercise

PPS Previous Year Question Papers

Data Types in C

Each variable in C has a data type. It defines the memory size of the variable along with the type of values, the variable can hold. We can Classify C data types as below:
DigitalG1 Classification of Data Types in C
Classification of Data Types in C

Primary Data Type

Primary data types are also called basic or primitive data types. These data types are further classified into four categories:

Integer Data Type

A variable of integer data type can hold an integer number as a value. Integers are the whole numbers that do not have any fractional or exponential part. These numbers may be positive or negative. Memory size and range of integer data types are machine-dependent. For example size of integer data type for a 16-bit machine is 2 bytes whereas, for a 32-bit machine size, it is 4 bytes. We use the keyword int to represent integer data type. We can declare integer variables as:

int num; or int num1, num2; or int num1 = 7, num2 = 5;

Floating Point Data Type

Variables of the floating-point data type can hold the real numbers. These numbers also may be positive or negative. Unlike integers, these numbers have a decimal point and expressed either in decimal or exponential form. The exponent form is used, when the data value given to the variable is very small or very big. For example, the value 0.00000000000034 can be written as 3.4 x 10-13, and in exponent form, it is represented as 3.4E-13. Because of the shifting of a decimal point either to the left or to the right during the manipulation, these are also called floating points. The floating-point has two different flavors:
  • float
  • double
Keyword float is used to represent a single-precision floating-point whereas double is used to represent a double-precision floating-point. Variables of float data type can store the value accurately up to six decimal places but the variable of double data type can store up to 16 significant digits after the decimal point. We can declare floating-point variables as:

float g = 9.8; or double dis = 2.5E-52;

Character Data Type

A variable of character data type can hold a single character. It actually stores the ASCII (American Standard Code for Information Interchange) value of character which is an integer. Moreover, it can be used as an integer in arithmetic expressions. Keyword char is used to represent character data type. We can declare character variables as:

char ch = ‘A’; or char in = 65;

Void Data Type

The void is an empty data type that represents nothing or no value. It is used as a function parameter and as a function return type. It also used to define void pointers. We will study it in detail later.

Data Type Qualifiers or Modifiers

Qualifiers are used to modify the properties of a primary data type to transform it into a new data type. Some keywords such as long, short, unsigned, etc are used for this purpose. These keywords prefixed with data types for the alteration. There are four types of qualifiers:
  1. Size Qualifier
  2. Sign Qualifier
  3. Constant Qualifier
  4. Volatile Qualifier

Size Qualifiers

Size qualifiers modify the size of primary data types. Two keywords are used as size qualifiers:
  • long
  • short
Keyword long increases the size of data type whereas short decreases. Example:

long double dis;

In this example size of the double data type variable is 8 bytes, but when we use long prefix variable size increased to 10 bytes.

Sign Qualifiers

Sign qualifiers decide whether a variable can store only the positive values or both positive and negative values. Following keywords are used as sign qualifiers:
  • signed
  • unsigned
The signed keyword is used with those variables that can store both positive and negative types of values whereas unsigned variables can store only positive values. Example:

signed int balance;
unsigned age;

In the above examples, the balance could be positive or negative, but age could not be negative.

Note: Variables without any sign qualifier are treated as signed variables.

Constant Qualifiers

The constant qualifier can transform any variable into a constant. Keyword const is used for it. The value of such type of variable is initialized at the time of declaration and it will not be changed during the execution of the program. Example:

const float pi = 3.1415;

Volatile Qualifiers

Volatile qualifiers are used to transform a variable such that it’s value can be modified anytime by some external sources outside the program. Keyword volatile is used to declare volatile variables. Example:

volatile int cost;

Following is a list of primary data types with their qualifiers, keywords, size, range, and format specifiers:
Data Type Keyword Size (in Bytes) Range Format Specifier
Integer (Signed) int or signed int 2 -32768 to 32767 %d or %i, %o, %x
Unsigned Integer unsigned int 2 0 to 65535 %u
Short Integer (Signed) short int or signed short int 2 -32768 to 32767 %d or %hi
Unsigned Short Integer unsigned short int 2 0 to 65535 %u or %hu
Long Integer (Signed) long int or signed long int 4 -2147483648 to 2147483647 %ld or %li
Unsigned Long Integer unsigned long int 4 0 to 4294967295 %lu
Floating Point float 4 -3.4e38 to 3.4e38 %f, %e or %E or %g or %G
Double double 8 -1.7e308 to 1.7e308 %lf
Long Double long double 10 -1.7e4932 to 1.7e4932 %Lf
Character (Signed) char 1 -128 to 127 %c
Unsigned Character unsigned char 1 0 to 255 %c

Note: Given sizes and ranges are for a 16-bit machine.

Derived Data Type

Derived data types are derived from the primary data types. These are the following:
  • Pointer
  • Array
  • Function

We will discuss Pointer, Array, and Function in detail later.

User-Defined Data Type

In C, programmers can define their own data types as required. User-defined data types are the following:
  • Structure
  • Union
  • Enumeration or Enum

We will discuss Structure, Union, and Enumeration in detail later.

Aditya Saini

Please Share:

Leave a Comment

Your email address will not be published.

Scroll to Top