Describe the basic data types used in C language.



Data types in C language can be classified into the following categories.
 1. Primary Data type
 2. User Defined Data type
 3. Derived Data type
 4. Empty Data set.

 Primary Data type
1) int
2) float
3) double
4) char
int: These are whole numbers, both positive and negative. Unsigned integers (positive values only) are supported. In addition, there are short and long integers. Its data range is -32768 to +32767
The keyword used to define integers is: int.
An example of an integer value is 32. An example of declaring an integer variable called sum is:
            int sum;
            sum = 20;

float: These are numbers which contain fractional parts, both positive and negative. The keyword used to define float variables is: float. Its data range is -3.4e38 to +3.4e38.
An example of a float value is 34.12. An example of declaring a float variable called money is:
            float money;
            money = 0.12;
double:double is used to define BIG floating point numbers. It reserves twice the storage for the number. Its data range is -1.7e38 to +1.7e38. An example:
        double Atoms;
        Atoms = 2500000;
   

Char: These are single characters. The keyword used to define character variables is: char
An example of a character value is the letter A. An example of declaring a character variable called letter is:
char letter;
            letter = 'A';

 USER DEFINED DATA TYPE
 User defined data type are those which are derive from the basic data types. Some of the user defined data types are
1) Type definition
2) Enumerated
Type definition: In C language a user can define an identifier that represents an existing data type.
The user defined data type identifier can later be used to declare variables.
Syntax is: typedef datatype identifier;
     Example:
     typedef int marks;
     Now marks can be used  to declare integer variables as
     marks mark1,mark2;
Enumerated: Enumerated data types are those in which a variable can contain only some specific set of values. This is done using the key word “enum”.
 example:
 enum months = { “January”, “Feburary”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December” };
 months m1, m2;
 here the variables m1 and m2 are of enumerated data types. It can hold only the values from January to December as declared.


Derived Data type:
 1) Arrays
 2) Structures
 Arrays
 Arrays can be defined as the collection of similar type of data. It can also be called as subscripted variables.
 example:
 int Mark[100];
 here the variable mark is defined as an array and it can hold 100 values of type integer. Each value can be accessed as Mark[0], Mark[1], ……. Mark[99]
 Structures
 Structures are nothing but a collection of data items. Unlike in arrays, it can hold set of data items of different data types under a single name. This data type can be created using the keyword “struct”
 example:
 struct student
 {
 int rno;
 char name[25];
 float avg;
 };
 struct student s1, s2;
 In the above example, student is an user defined data type. The structure variable s1 consist of 3 values namely rno, name and avg.

EMPTY DATA SET:
As the name indicates, it contains nothing or a NULL value. This data type is used to specify return values of function. If there is nothing to return from a function, the return type can be specified as “void”

 example:
 void main()
 {
 -----

 ------
 }
Next Post Previous Post
No Comment
Add Comment
comment url