Thursday, 20 December 2018

Datatypes

Datatypes :
Data type is the description of nature of data either in numeric form or in character form. It defines a set of values and the operations that can be performed on them. C supports different classes of datatypes. They are :         
                                                                                                                                                                                                                 
                                                                                 

·         Integer type are defined by the keyword int.
Ex:   int a;
·         Character type are defined by the keyword char.
Ex:   char name;
·         Float type are defined by the keyword float.
Ex:    float average;
·         String type are defined as char str[n];
Ex:     char name[5];
Void :
                The data type has no values. Void is a data type that which doesnot return any value to the calling function.
               The memory requirements for each data type will determine the permissible range of values for that type, which may vary from one compiler to another. The size and range of these data types differ which are shown below :
DATA TYPE
SIZE (Bytes)
RANGE
char or signed char
1
-128 to 127
unsigned char
1
0 to 255
int or signed int
2
-32,768 to 32,767
unsigned int
2
0 to 65,535
short int or
signed short int
1
-128 to 127
unsigned short int
1
0 to 255
long int or
signed long int
4
-2,147,483,648 to
2,147,483,647
unsigned long int
4
0 to 4,294,967,295
float
4
3.4e-38 to 3.4e+38
double
8
1.7e-308 to 1.7e+308
long double
10
3.4e-4932 to 1.1e+4932
 1.      User-Defined Data Type :
1.      typedef:
      C supports a feature known as “ typedef (type definition) “ that allows users to define an identifier that would represent an existing data type which can later be used to declare variables. It is represented as
             typedef   type   identifier
                               where  type  refers to an existing data type and  identifier  refers to the new name
                               given to the data type.
                            Ex : typedef   int   marks;
                 
                               Here marks symbolizes int. so that they can be later used to declare variables as
                                        marks section1,section2;
                                where section1 and section2 are  int data type.

1.      Enumerated :
Another user-defined data type is  “ enum “ (enumerated) data type. It is defined as

              enum identifier {value1, value2, . . . . . valuen};

where identifier is user-defined enumerated data type which can be used to
                      declare variables that can have one of the values enclosed within braces.
                                        Ex : enum  Boolean { true, false };
                                             enum Boolean t, f;
  t=true;     f=false; So that the compiler will automatically assigns integer values beginning with 0. That is the enumeration constant true is assigned 0, false assigned 1. 
 Declaring the Variables :
After defining the variable names, they must be declared to the compiler as it reserves some memory and also specifies what type of data the variable will hold.
 A variable can be used to store a value of any data type. Variable must be separated by comma.  All declarations must be terminated by a semicolon (;).
The syntax for declaring a variable is :
                                data type variable1,variable2, . . . . . variable n;
Ex : int total;
                Two types of variable declaration can be done. They are:
1.      Local Variables
2.      Global variables
Local Variables :
        "Variables that are declared inside a function are called local variables.
                Ex :             #include <stdio.h>
                                   main()
                                   {
                                         int a,b,c;                             these are local variables
                                  }
                Global Variables :
                                Global Variable can be accessed throughout the entire program and may be used by any piece of code. Global variables are created by declaring them outside of a function.
                                Ex:             #include<stdio.h>
                                                       int a;                                 these are global variables
                                                    main()
                                                {
                                                                int b,c;                                  these are local variables
                                                   }          

DATA TYPE
KEYWORD
character
char
integer
int
floating point
float
double floating point
double
unsigned character
unsigned char
signed character
signed char
signed short integer
signed short int or short
signed long integer
signed long int
unsigned integer
unsigned int
unsigned short integer
unsigned short int
unsigned long integer
unsigned long int
extended double floating point
long double















  

No comments:

Post a Comment