#include<stdio.h> int main() { char c = ‘a’; int a = 321, b, i; unsigned m = 65535, n; float x = 2.5, y; double d = 12345678.987; printf(“c=%c, a=%d, m=%u, x=%f, d=%f\n”, c, a, m, x, d); c = a; /*整型转到字符型,整型变量a的值321存放到字符型变量c,只保留低八位01000001,即十进制数65*/ b = x; //单精度转到整型,单精度变量x的值2.5存放到整型变量b,只保留整数部分2 y = a; /*整形转到单精度,整型变量a的值321存放到单精度变量y,数值321不变,但以实数形式存储到变量中*/ x = d; /*双精度转到单精度,双精度变量d的值12345678.987,小数部分四舍五入处理进到整数部分,再以实数形式储存到变量中*/ i = m; //无符号整形转到整型,直接转 n = -1; //负数赋值给无符号整型,-1的补码4294967295存入无符号整型变量 printf(“c=%c, b=%d, y=%f, x=%f, i=%d, n=%u\n”, c, b, y, x, i, n); getchar(); return 0; }
时间: 2024-10-18 20:58:24