Type Casting

Type Casting is convert one datatype to another datatype. If you want to store long value into the integer then you can type cast ‘long’ to ‘int’. We can use cast operator for typecasting which is denoted by (type).In typecasting we are always convert the lower value to higher value for avoiding data loss.

Syntax

(type_name) value;

Type Casting Example

Let’s see example to add character ASCII value to integer.

#include <stdio.h>
main() {
   int  number = 1;
   char character = 'k'; /*ASCII value is 107 */
   int sum;
   sum = number + character;
   printf("Value of sum : %d\n", sum );
}     

Output

Value of sum : 108

Submit your review
1
2
3
4
5
Submit
     
Cancel

Create your own review

The Technical Funda
Average rating:  
 0 reviews