Datatypes in c language
Datatypes in c language

C has a concept of ‘data types’ which can used to define a variable before its use.C data types are defined as the storage format of the data that a variable can store a matter of performing a specific task. The data types are used to define a variable before using in a program. Dimensions of variable, constant and the matrix are determined by the data type. You can also that The value of a variable can be changed any time.

NO.TYPESDATA TYPES
1Basic Data Typesint, char, float, double
2Derived Data Typepointer, array, union, structure
3Enumeration Data Typeenum
4Void Data Typevoid

 

 

1. BASIC DATA DYPE

c has int , float , char , double etc basic type in c language. The definition of a variable will assign storage for the variable and define the type of data that will be held in the location. The value of a variable can be changed any time. basic data type are in table his range , keyword , its memory.

VARIABLE TYPE.KEYWORDBYTES REQUEREDRANGE
Characterchar1-128 to 127
Unsigned Characterunsigned char10 to 255
Integerint2-32768 to 32767
Short Integershor int2-32768 to 32767
Long Integerlong int4-21,47483648 to 2147483647
Unsigned Integerunsigned int20 to 65535
Unsigned Short Integerunsigned short int20 to 65535
Unsigned Long Integerunsigned long int40 to 4294967295
Floatfloat41.2E-38 to
Doubledouble82.2E-308 to
Long Doublelong double103.4E-4932 to 1.1E+4932

 

  • Character Data Type :-

char define Character data type. Character data type allows a variable to store only one character. storage size of char data type is 1. We can store only one character using char data type. char keyword is used to refer character data type.

Syntax :-

Example :-

 

  • Integer Data Type :-

Int defines Integer data type in c language . integer data type is store numeric value like 1,2,3,4.. .integer data type is can’t store decimal value. integer data type example and syntax are as under.

Syntax :-

Example :-

 

  • Float Data Type :-

Float data type allows a variable to store decimal values. storage size of float data type is 4. This also varies depend upon the processor in the CPU. We can use upto 6 digits after decimal using float data type. float datatype example and syntax as under.

Syntax :-

Example :-

 

  • Double Data Type :-

Double data type is also same as float data type which allows upto 10 digits after decimal. and the range is from 1E–37 to 1E+37.

Syntax :-

Example :-

 

2. ENUMERATION DATA TYPE:-

Enumeration data type består named integer constants as a list. It start with 0 (zero) by default and value is incremented by 1 for the sequential identifiers in the list.

Syntax :-

Example :-

Output :-

Day is tus

 

3. DERIVED DATA TYPE:-

Derived tata type has array , pointer , structur , union. derived data type are explain one by one with example as under .

    • Array :-

Array is collection of Elements.An array in C language is a collection of similar data-type betyder an array kan keep the value of a særlig data type for som det Declared. Arrays kan created from any of the C data types int, float and char. So an integer matrix kan only hold integers and can not hold values ​​other than integers. When we declare array, it allocates contiguous memory for storing values ​​considerations 2 or 3 variables of the same data type kan random places. So this is the main differencebetween a variable and a matrix.An array is a collection of values, all of the same type, stored contiguously in memory. C Array is a collection of variables belongings to the same data type. You can store group of data of same data type in an array.

two types of array in c language.

1.Single dimensional array

2.Multi dimensional array (Two dimensional array )

1.Single dimensional array
Array might be belonging to any of the data type. Array size must be a constant value.single dimensional Arrays are initialized with a list of values.

Syntax :-

Example :-

Output :-

value of arr[0] is 2

value of arr[1] is 3

value of arr[2] is 4

value of arr[3] is 5

2.Multi dimensional array
multi dimensional array is also call Two dimensional array. It is nothing but array of array.Multi dimensional Array might be belonging to any of the data type.Array size must be a constant value.

Syntax :-

Example :-

Output :-

value of ar[0][0] is 4

value of ar[0][1] is 3

value of ar[1][0] is 2

value of ar[1][1] is 1

    • Structure :-

Structures are a way store flera pieces of data I E variable. For example say we Desired to Save name and birthday as someone I Strings In E variable. We could use one structure til Houses disse data:

Syntax :-

Example :-

Output :-

(*ptr).a is same as ptr->a

(*ptr).b is same as ptr->b

    • Pointer :-

A pointer is a variable whose value is the address of another variable ie. direct address of the memory location. Like any variable or constant, you must declare a pointer before you can use it to store any variable address. The general form of a pointer variable declaration is as under.

Syntax :-

Example :-

Output :-

[c], [20], [1.200000], [I], [I am a string]

    • union :-

C is also the structure of the Union, that is, a collection of different data types, which are grouped together and each element is called the Federal member.

Syntax :-

Example :-

Outout :-

Name is:Raju

Percentage is: 86.500000

 

More C Tutotrial at : C Programming on Ubuntu

Datatypes in c language
Datatypes in c language