Data Types in C
->Watch this for FUN - Funny job interview
Are you getting bored with online lectures?
->Watch this - When online lectures are boring
Data types are the building blocks of any programming language. It is the most important topic in C, without data types there couldn't be any foundation of C programming language.
So, now let's move on to the types of Data types in C.
<><><><><><><>
There are three types of data types in C:
1) Primitive data types.
2) Derived data types.
3) User-defined data types.
So, let's explore what each one is about:
1) Primitive Data Types
Primitive data types in C programming language includes int, char, float, void.
The int data type is used for the declaration of integer variables like:
int x=10; // integer x takes value 10
The char data type is used for the declaration of character variables like:
char x='a'; // character x takes value a
The char data type is used for the declaration of float(decimal point integers) variables like:
float f=23.6; // variable f takes value 23.6
The void data type is empty i.e. it takes no value, it is generally used for the calling of the function that returns no value. For calling of function refer to this.
<><><><><><><>
2) Derived data types
These data types are derived from the primitive ones which include strings, pointers, function, arrays.
An array in C is a collection of items stored at contiguous memory locations and elements can be accessed randomly using its indices. The array could be an integer array or character array or float array whose declaration is
int a[200]; // Here it would create a 1-D integer array of size 200.
The string data type is the array of characters. The string is one of the derived data types which is derived from char(a primitive data type) whose declaration is:
char a[some value]; // Here it would create a character array of size=value specified
Functions are the block of code that performs a specific task given to it as an argument which can be found here.
The pointer is a variable that contains the address of some other variable, once pointed it would output the value stored in that other variable like
int *a; // Declaration of an
a=&b; // a pointing to b by taking its address(A variable address is represented by &)
3) User-defined Data Types
These data types are declared to ease the work of storing many primitive and derived data types into one data type which includes structures, unions, enum, and typedef.
For structure, refer to this.
Enum declaration is the same as a structure but to decrease the storing capacity, the data types are declared in enum share space. Its declaration is
union store{
int a;
char b;
}; // Here sharing takes the priority of the data type.
Enum(Enumeration) is used to assign names to the integral constants which makes a program easy to read.
Its declaration is:
enum name{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, sunday};
So, here Monday takes value 0, Tuesday 1, and so on...
But f you declare the enum like
enum name{Monday, Tuesday, Wednesday=10, Thursday, Friday, Saturday, sunday};
Here Monday takes 0, Tuesday 1, Wednesday 10, Thursday 11 and it continues.
Typedef is a data type used to give a nickname to a variable.
typedef int name; // After its declaration name would act as an integer data type.
name k=10; //name acts as integer
Watch this for FUN - Funny job interview
Are you getting bored with online lectures?
Watch this - When online lectures are boring
<><><><><><><>
<><><><><><><>
Comments
Post a Comment