Hello, friends, this is Ujjwal Sinha, in today’s article I will discuss about Data type and its use in C language. So without wasting time let’s begin…
EX.
SYNTAX: typedef datatype name;
Example:
SYNTAX: enum datatype_name {value 1,value 2,value 3,…….value n};
Example:
Empty Data set: void null,\0 are three members of the empty data set.
Data type:
C language is rich in its data type. The variety of datatype available in C allows the programmer to select the appropriate type according to the need of the application. ANSIC supports four classes of datatypes.Data type and its uses in C |
Primary/ fundamental Datatype:
The data type which represents the fundamental data i.e. characters and numbers and are already defined to the compiler is known as the primary data type. Integers, Characters and float are primary data types in C language. Some of these data types are further divided into different categories like signed, unsigned, short, long etc. The following chart represents the classification of basic datatype and their size. Symbol and range.
Type
|
Size (byte)
|
Symbol
|
Range
|
Char/signed char
|
1
|
%c
|
-128 to 127
|
Unsigned char
|
1
|
%c
|
0 to 255
|
Short int/signed short int
|
1
|
%hd
|
-128 to 127
|
Unsigned short int
|
1
|
%h
|
0 to 255
|
Int / signed int
|
2
|
%d
|
-32768 to 32767
|
Unsigned int
|
2
|
%u
|
0 to 65535
|
Long int/ signed long int
|
4
|
%ld
|
-2,147,483,648 to 2,147,483,647
|
Unsigned long int
|
4
|
%lu
|
0 t0 4,294,967,295
|
Float
|
4
|
%f
|
-3.4e38 to 3.4e38
|
Double
|
8
|
%lf
|
-3.4e308 to 3.4e308
|
Long double
|
10
|
%Lf
|
-1.7e4982 to 1.7e4982
|
Derived datatype:
The datatypes which are derived from primary data types are called derived datatype, array, pointer, structure, union, etc. are derived datatype.EX.
int a[10];
int *ptr;
struct mixed
{
int x;
char y;
float z;
}
v1, v2;
User-Defined Datatype:
there are two ways to create user-defined datatype-
Using typedef statement – C supports a feature known as type definition that allows a user to define a new name to represent an existing primary or derived datatype.SYNTAX: typedef datatype name;
Example:
- typedef int integer;
- typedef unsigned long int uh;
- Using enum statement- In addition to typedef statement C allows another user-defined datatype enumerated datatype which can be created using the enum keyword
SYNTAX: enum datatype_name {value 1,value 2,value 3,…….value n};
Example:
- enum days {Sunday, Monday, Tuesday, Thursday, Friday, Saturday};
- enum days holiday= Sunday;
- enum months { January , February,………………..,December};
- enum months summer= June;
Empty Data set: void null,\0 are three members of the empty data set.
Operators
In the previous article, some instructions about operators and in this article we learn about types of operators use in C language.TYPES OF OPERATORS:
C supports the number of operators that can be classified into various categories based on their utility and actions. There are eight categories of operators which are the following:- Arithmetic operators.
- Relational Operators.
- Logical Operators.
- Increment and decrement operators.
- Assignment Operators.
- Conditional Operators.
- Bitwise operators.
- Special Operators.
Some C programming related arithmetic operators.
Write a program in C language to input three numbers and print sum and average.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,sum=0 ;
float avg=0 ;
clrscr();
printf(“Enter first number”);
scanf(“%d”,&a);
printf(“Enter second number”);
scanf(“%d”,&b);
printf(“Enter third number”);
scanf(“%d”,&c);
sum=a+b+c;
avg=sum/3;
printf(“Sum=%d”,sum);
printf(“Average=%f”,avg);
}
getch();
Write a program in C to input two numbers and print its subtraction.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,sub=0 ;
clrscr();
printf(“Enter first number”);
scanf(“%d”,&a);
printf(“Enter second number”);
scanf(“%d”,&b);
sub=a-b;
printf(“Subtraction=%d”,sub);
}
getch();
Write a program in C input two numbers and print multiplication.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,multiply=0 ;
clrscr();
printf(“Enter first number”);
scanf(“%d”,&a);
printf(“Enter second number”);
scanf(“%d”,&b);
multiply=a*b;
printf(“Multiplication=%d”,multiply);
}
getch();
Write a program In C input two numbers and print its division and reminder.
#include<stdio.h> #include<conio.h> void main() { int a,b,div,rem=0 ; clrscr(); printf(“Enter first number”); scanf(“%d”,&a); printf(“Enter second number”); scanf(“%d”,&b); div=a/b; rem=a%b; printf(“Division=%d”,div); printf(“Reminder=%d”,rem); } getch();
0 Comments
Enter your message here