TUTORIALS

Data Types in C

Written By: Chaitra M
Created at: 28-June-2023 20:36:19
Modified at: 28-June-2023 20:36:39

Data refers to some specific values used in a program. Data can be either a variable or a constant. The two fundamental data types used in C are integer and floating point. Other types are derived from the fundamental types.

Primitive Data Types

Integer

An integer value refers to a whole number. It may be positive or negative numbers. Integer data type in C program accepts to store only integer values in the variables.
Integer values range from -32768 to +32767 for a signed integer. Negative integer is represented by attaching a '-' (minus) sign to the number. Where as to represent a positive integer '+' (plus) sign is not used as it is illegal according to C programming. Any number represented without sign then it implicitly refers to positive number. If we try to store any decimal number then there is a spill of data and the exponent values will be lost.

Syntax:

int identifier_name;

int is a keyword used to define integer data type and identifier_name is the variable name.
Examples:
Example 1:

int a;
Integer Variable Representation

Integer Variable Memory Representation before initialization


Example 2:

int b = 10;
Integer Variable Representation

Integer Variable Memory Representation after initialization

Example 2, shows an integer constant 'b' with value 10 initialized.

In the examples shown, Example 1, it shows a variable 'a' of type integer declared and it doesn't have value stored in it. Whereas Example 2, shows an integer constant 'b' with value 10 initialized.

Floating Point

Floating point data type stores both integer as well as decimal numbers. Floating point as the name itself defines the point is floating or at variable location.

Double Precision


Double stores larger floating point values.

Character Type


Character type stores any character.

Data Type representation chart

Representation of different data types:

Sl. No.KeywordType of data handledSize of data typeFormat Specifier
1charCharacter type.-128 to 127 or 0 to 255%c
2unsigned charUnsigned character type.0 to 255%c or %hhu
3signed charSigned character type.-128 to 127%c or %hhi
4signed int intSigned Integer type.
5signed short int short intSigned Short Integer type.
6signed long int long int longSigned Long Integer type.
7unsigned int unsignedUnsigned Integer type.
8unsigned short int unsigned shortUnsigned Short Integer type.
9unsigned long int unsigned longUnsigned Integer type.
10floatFloating point decimal value.
11doubleDouble precession floating point decimal value.
12long doubleExtended double precision floating point decimalvalue.

Derived Datatypes

Arrays

Arrays are sequential memory locations under the same name. This section is covered in Arrays in-detail.

Pointers

Pointer data types are variables that holds address location of another variable. This section is covered in coming chapter in-detail.

User-Defined Datatypes


Structure

Union

Enumerated

There are no likes. Be the first one to like
Likes: 0
Comments: 0