What are the data types and how many types of it? - Study24x7
Social learning Network

Welcome Back

Get a free Account today !

or

Forgot password?

By Registering, you agree to our Privacy Policy and Terms of use.

What are the data types and how many types of it?

Updated on 10 June 2020
study24x7
COMPUTER PROGRAMMING 2020
7 min read 3 views
Updated on 10 June 2020

In programming, data types are declarations for variables. This determines the type and size of data associated with variables.


In JAVA, Data types in two groups:-


1.Primitive data types :-


Byte, short, int, long, float, double, char and boolean


 2.Non-primitive data types :-


string, arrays, class


 Data Type in C++


1.User derived Data Type- Structure, Union, Enum

2.Built in Data Type- int, char, float, double Boolean, void, wide character

3.Derived Data Type- Array, Function, Pointer



Size and Range of Data Types in C

Type
Size(bits)
Range
Char or signed char
8
-128 to 127
Unsigned char
8
0 to 255
Int or signed int
16
-32,768 to 32,767
Unsigned int
16
0 to 65535
Float
32
3.4E -38 to 3.4E +38
Double
64
1.7E – 308 to 1.7E + 4932


Integer Data Type:-


Integers are whole numbers with a range of values.  It represented by int. In C, There are three classes of integers storage, that are short int, int and long int in both signed and unsigned forms

Commas, decimals and special signs not allowed.

Examples:-

VALID
0
5
-10
+24
1000
+47
INVALID
$4567
2.4
1,456
9.
1,789.50
9,567,560


Example:-

int num = 100;


Characters


The char data type is used to store a single character. Characters are usually stored in 8 bits (1 byte) of internal storage. The character represented by single quotes, like 'A' or 'd'


Float


Floating point numbers are defined by keyword float

Examples:

float num = 1.789;

double num = 10008.90898;


void type


It has no value. This is usually used to specify the type of functions. The type of the function is to be void


DATA TYPES and VARIABLES declaration in C


Example


int a = 4000; // positive integer data type

float b = 5.789; // float data type

char c = 'p'; // char data type

long d = 41657; // long positive integer data type   

int e = -185; // -ve integer data type

double f = 4.1234567890; // double float data type

float g = -3.55; // float data type


User-Defined Data Types:


These data types are defined by user itself. Like, defining a class in C++ or a structure. In C++ there are different user defined data types:


·Class

·Typedef defined DataType

·Structure

·Union

·Enumeration

               

In C , Some examples of type definition are:-


typedef int units;

typedef float marks;

Here, units symbolizes int and marks symbolizes float. They can be later used to declare variables:-

units batch1, batch2;

marks name1[50], name2[50];

Another user defined data type is enumerated data type :-

Enum identifier {value1, value2,…valuen};


Derived Data Type-

Array, Function, Pointer


Data Types
Description
Arrays
Arrays are sequences of data items having homogeneous values. They have adjacent memory locations to store values.
Pointers
In C , which are used to access the memory and deal with addresses.



NOTE:-Keep visit to learn the Benefits of Computer Programming


For more information you can visit this page


COMPUTER PROGRAMMING 2020

 


study24x7
Write a comment...