问题描述
该程序演示了从一本书中使用的工会计划
为什么如果我更改程序中的一个字符我会收到以下错误
list10 -6.c:14:20:警告:多字符字符常量
list10-6.c:在函数main中:
list10-6.c :14:警告:隐式恒定转换溢出
程序低于违规行,第14行是字符
是$改为?£
/ * LIST10-6..C一次使用超过一个联盟成员的例子* /
#include< stdio.h>
int main(无效)
{
union shared_tag {
char c;
int i;
long l;
float f;
double d;
}已分享;
(14); shared.c =''$'';
printf(" \ nchar c =%c",shared.c);
printf( " \ nint i =%d",shared.i);
printf(" \ nlong l =%ld",shared.l);
printf(" \ nfloat f =%f",shared.f);
printf(" \ nouble d =%f",shared.d);
shared.d = 123456789.8765;
printf(" \ nchar c =%c",shared.c);
printf(" \ nint i =%d",shared.i);
printf(" \ nlong l =%ld",shared.l);
printf(" \ nfloat f =%f",shared.f);
printf(" \ nouble d =%f \ n",shared.d);
返回0;
}
The program demonstrates the use of unions program taken from a book
why if i change one character in a program i get the following error
list10-6.c:14:20: warning: multi-character character constant
list10-6.c: In function `main'':
list10-6.c:14: warning: overflow in implicit constant conversion
the program is below the offending line, is line 14 the character
is $ changed to ?£
/* LIST10-6..C EXAMPLE OF USING MORE THAN ONE UNION MEMBER AT A TIME */
#include<stdio.h>
int main(void)
{
union shared_tag{
char c;
int i;
long l;
float f;
double d;
}shared;
(14); shared.c = ''$'';
printf("\nchar c = %c",shared.c);
printf("\nint i = %d",shared.i);
printf("\nlong l = %ld",shared.l);
printf("\nfloat f = %f",shared.f);
printf("\ndouble d = %f",shared.d);
shared.d = 123456789.8765;
printf("\nchar c = %c",shared.c);
printf("\nint i = %d",shared.i);
printf("\nlong l = %ld",shared.l);
printf("\nfloat f = %f",shared.f);
printf("\ndouble d = %f\n",shared.d);
return 0;
}
推荐答案
这篇关于为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!