Type Casting में एक variable को दूसरे variable में convert किया जाता है |
For example अगर किसी variable को integer से float या float से integer में convert किया जाता है, तो उसे Type Casting कहते है |
Source Code :
Source Code :
For example अगर किसी variable को integer से float या float से integer में convert किया जाता है, तो उसे Type Casting कहते है |
| int | float |
Syntax for Type Casting
(data_type_name) expressionSource Code :
#include <stdio.h>
int main(){
int a, b;
float c;
printf("Enter value of a : ");
scanf("%d", &a);
printf("Enter value of b : ");
scanf("%d", &b);
c = (float) a / b;
printf("%f", c);
return 0;
}
Output :
Enter value of a : 15 Enter value of b : 6 2.500000
Float to Integer
| char | int |
#include <stdio.h>
int main(){
char c = 'a';
printf("ASCII value of %c is %d", c, c);
return 0;
}
Output :
ASCII value of a is 97







No comments: