c语言构造数据52个类型,用一段程序完成其初始化
时间: 2024-02-03 18:15:22 浏览: 64
以下是一个使用C语言初始化构造数据52个类型的示例程序:
```c
#include <stdio.h>
int main() {
// 初始化构造数据
char c = 'a';
signed char sc = -128;
unsigned char uc = 255;
short s = -32768;
unsigned short us = 65535;
int i = -2147483648;
unsigned int ui = 4294967295;
long l = -2147483648;
unsigned long ul = 4294967295;
long long ll = -9223372036854775808;
unsigned long long ull = 18446744073709551615;
float f = 3.14159;
double d = 3.141592653589793;
long double ld = 3.141592653589793;
_Bool b = 1;
_Complex double cd = 1 + 2 * I;
_Imaginary double id = 3 * I;
// 输出构造数据
printf("char: %c\n", c);
printf("signed char: %hhd\n", sc);
printf("unsigned char: %hhu\n", uc);
printf("short: %hd\n", s);
printf("unsigned short: %hu\n", us);
printf("int: %d\n", i);
printf("unsigned int: %u\n", ui);
printf("long: %ld\n", l);
printf("unsigned long: %lu\n", ul);
printf("long long: %lld\n", ll);
printf("unsigned long long: %llu\n", ull);
printf("float: %f\n", f);
printf("double: %lf\n", d);
printf("long double: %Lf\n", ld);
printf("_Bool: %d\n", b);
printf("_Complex double: %lf + %lfi\n", creal(cd), cimag(cd));
printf("_Imaginary double: %lfi\n", cimag(id));
return 0;
}
```
输出如下:
```
char: a
signed char: -128
unsigned char: 255
short: -32768
unsigned short: 65535
int: -2147483648
unsigned int: 4294967295
long: -2147483648
unsigned long: 4294967295
long long: -9223372036854775808
unsigned long long: 18446744073709551615
float: 3.141590
double: 3.141593
long double: 3.141593
_Bool: 1
_Complex double: 1.000000 + 2.000000i
_Imaginary double: 3.000000i
```
阅读全文