Data type: is used to define the type of data that a variable can hold. For example: An integer variable can hold integer type data, a character variable can hold character type data, a float variable can hold float type data etc.
For Example: int is a data type used to define integer type variables. int a here, a is a variable of int (integer) type. It can store numbers from -2,147,483,648 to +2,147,483,647. And the size of int is 4 bytes.
Note: every variable which is to be used in the program must be declared as what data type it is.
C language has some set of predefined data types to handle various kinds of data that we can use in our program. These data types have different storage capacities.
C language supports different types of data types:
- Primary or Primitive data types: These are fundamental data types in C namely integer (int), floating point (float), character (char), double and void. Primary is also known as built-in or pre-defined data types.
- Derived data types: Array, pointer, and function.
- User defined data type: This data types are nothing but primitive data types, but a little twisted or grouped together such as Structure, Union, Enum.
Built-in or Primitive data type:
Primitive types are the most basic data types in c programming language. such as int, char, float, double, void. Primitive data types are also known as predefined data type or basic data types.
Note: The memory size of basic data types may change according to 32 bit to 64 bit operating system.
Let's see the list of pre-defined or basic data type.
int (Integer type):
In C programming, int (stands for integer) is a keyword used to define integer type variables before to use in a program.
Size of int is 2 or 4 bytes (according to 32 bit or 64 bit operating system) Older system stored int as 2 bytes within a range of -32,768 to 32,767. But now it's takes up 4 bytes and can range from -2,147,483,648 to 2,147,483,67.
For Example: int is a data type used to define integer type variables. int a here, a is a variable of int (integer) type. It can store numbers from -2,147,483,648 to +2,147,483,647. And the size of int is 4 bytes.
char (character type):
Any character value in C stores a singal character and requires a singal byte (1 byte) of memory in almost all compilers within a range -128 to 127.
For Example: char grade = 'A' where grade is defined as character type variable it can store any value of char type within char range as mentioned above.
float double and long double type:
Real numbers are represented in C with keywords float, double and long double. float defines a singal precision floating point number that can store 1.2E-38 to 3.4E+38. Whereas double defines double precision floating point numbers that can store 2.3E-308 to 1.7E+308.
Precision: Number of digits after the decimal point is called precision. For example: 23.3456 has precision four and 23.34 has two precision. By default Float has 6 decimal digits of precision and double has 15 decimal digits of precision.
Example to define float type variables:
/*Float has 6 decimal digits of precision */
float average = 89.330000
/*Float has 6 decimal digits of precision */
double percentage = 93.330000000000000
void type:
In C programming, void means nothing, that means it does not store anything. It has different meaning in different places: When void is used as a function return type, it indicates that the function does not return a value. when void appears in a pointer declaration, it specifies that pointer is universal. When void is used in a function parameter list, it indicates that function takes no parameters.
For now you don't worry about void type, we will learn with example in later section of this programming tutorial.
User defined data type:
Those data types which are defined or created by the user using primitive data type as per our need are known as user defined data types. For example: Structure, Union, and Enumeration.
Let's understand with a simple example how to create a user defined data type:
struct student{
char name[50];
int roll;
float marks;
};
In above example, student is a new data type created by user with the help of primitive data types char, int and float.
- User defined data types: structure, union, enum
- Derived data types: array, function, pointer.
Read more about-
0 Comments:
Post a Comment
Please don't enter any spam link in the comment box.