Why typedef is used?
It is used the redefine the user define value in order to make a program more simple and reliable, it passes the user define value to a new value for the same data type (int, char, float, double, etc..)Syntax
Typedef <existing datatype><alias- name/ new define>
Code #include <stdio.h> void main() { typedef int number; // define number as a int. number a; // redefine 'a' as a number number b; // redefine 'b' as a number number sum = 0; printf("enter a value of a: "); scanf("%d", &a); printf("enter a value of b: "); scanf("%d", &b); sum = a+b; // sum up the value of a and b. // the addition value of 'a' and 'b' will replace in sum, as sum is '0' we have define up. printf("addition typedef value is %d", sum); }
#include <stdio.h>
void main()
{
typedef int number; // define number as a int.
number a; // redefine 'a' as a number
number b; // redefine 'b' as a number
number sum = 0;
printf("enter a value of a: ");
scanf("%d", &a);
printf("enter a value of b: ");
scanf("%d", &b);
sum = a+b; // sum up the value of a and b.
// the addition value of 'a' and 'b' will replace in sum, as sum is '0' we have define up.
printf("addition typedef value is %d", sum);
}
output
enter a value of a: 5
enter a value of b: 4
addition typedef value is 9
enter a value of a: 5
enter a value of b: 4
addition typedef value is 9
0 Comments