In most cases cast operator use to convert values form one variable type to another variable type.As an example if you want to find ASCII value of a character in C, you can use the cast operator to find it.. Below example will demonstrate the simple usage of Cast operator
/**************************************/
/* */
/* Operators Demo # 3 - Cast operator */
/* */
/**************************************/
#include <stdio.h>
main()
{
int i;
char ch;
printf("---------------------------------------------------------------\n");
printf("This program going to convert Charctor value to ASCI value\n\n");
printf("-----------------------------------------------------------------\n");
printf("Enter your Charctor:\n");
scanf("%c",&ch);
printf("Program detected your Letter as %c: ",ch);
printf("\n Ok... Now see the ASCII value");
i=(int) ch; /* This the cast operator*/
printf("ASCII value is %d:\n",i);
system("pause");
}

Categories :
1:25 AM

0 comments:
Post a Comment