Skip to content
HOME - C - What are the data types in programming languages

What are the data types in programming languages

what are the data types

Data types :

Data type defines the minimum and the maximum number of values and set of operations that can be performed on these values. These are of 2 types. Standard data type which is predefined or built-in available in the programming language. Standard data type includes int, char, float, double, etc.
User-define data type allows us to built our own data types.

Data type for characters ( char )

A keyword char is used for character datatype. It is used to represent a letter, symbol or number. This data type occupies 1 byte in memory. The format specifier used for char data type is %c in C language. while using this data type, a character is enclosed in apostrophes. For example, ‘x’, ‘a’, ‘G’, ‘=’, ‘$’, ‘8’ etc.

Keywords are of 2 types. Signed and unsigned keywords. Both can be used in this char data type. Signed characters represent numbers ranging from -128 to 127 and unsigned characters represent numbers ranging from 0 to 255. Characters are stored in the form of ASCII codes in the computer memory. Therefore, arithmetic operations can also be performed on these characters.

For example in the following program we are getting its ASCII value and character value.

#include <stdio.h>
#include <conio.h>
Int main()
{
char x;
X = ‘A’ ;
printf( “ Character value of x = %c \n“ , x) ;
printf( “ ASCII value of x = %d \n” , x);
getch();
}

Output

Character value of x = A
ASCII value of x = 65

Data types for Integers ( int )

Without decimal fraction numbers are integers. Integers may be positive, negative, or zero. It may be signed or unsigned. So if nothing mentioned, then it will be considered as signed numbers. int, short int, and long int are data types used for integers.

int data type

int data type takes 2 bytes in memory. It ranges from -2¹⁵ to 2¹⁵ -1. This data type can also be used as short int and signed int and can handle both positive and negative integers without decimal numbers.
The format specifiers for this data type is %d and %i . If an int variable stores a value having a decimal fraction, the compiler will ignore the numbers after coming to the decimal point. For example
int a = 10.56;
a will have 10 because its data type is int and will ignore remaining after the decimal point.

long int datatype

long int used to represent larger integers. It occupies 4 bytes in the memory. It stores numbers ranging from -2³¹ to 2³¹ – 1. So,  If we need a very large integer value then we will use long int instead of int data type.

Data types for decimal numbers

float data type

float data type is used to represent fractional numbers or decimal numbers. For example, 2.18, 0.888, 23.54 etc. It takes 4 bytes in memory. %f is the format specifier for the float data type. Its accuracy is up to 6 decimal places. If the value has more than 6 decimal places for float data type, then the compiler will ignore the remaining decimal places. For example
float d = 2.3145846345;
d will have a value of 2.314585 as float stores 6 decimal places.

double data type

For storing larger floating-point numbers, the double data type is used. This data type takes 8 bytes in memory. Its accuracy is up to 15 decimal places. The format specifier for the double data type is %lf.

Read our next article what are variables. You can watch the video about this here.

2 thoughts on “What are the data types in programming languages”

  1. Pingback: What are an expression, operators and operands in programming?

  2. Pingback: What is Type casting? Implicit type casting and Explicit type casting: | C

Leave a Reply

Your email address will not be published.

en English
X