
c语言求不同的数据类型在计算机中占的内存:
我想达到的目的是输入一个int就得到int在计算机中占的字节数,然后再输入float,得到float的字节数,但是我发现我写的这个程序不能实现目的:你们能帮我改改吗???...
我想达到的目的是输入一个int就得到int在计算机中占的字节数,然后再输入float,得到float的字节数,但是我发现我写的这个程序不能实现目的:你们能帮我改改吗???、、
#include<stdio.h>
void main()
{
int b;
char c[20];
while(1)
{
printf("\nenter the type of your data:");
gets(c);
puts(c);
b=sizeof(c);
printf("\n%d",b);
}
} 展开
#include<stdio.h>
void main()
{
int b;
char c[20];
while(1)
{
printf("\nenter the type of your data:");
gets(c);
puts(c);
b=sizeof(c);
printf("\n%d",b);
}
} 展开
3个回答
展开全部
sizeof不是根据“名称”来返回占内存多少,而是根据参数的数据类型来返回
你这里的 sizeof(c),就是返回 char c[20] 占多大空间,和c字符串的内容没有关系。
你这里的 sizeof(c),就是返回 char c[20] 占多大空间,和c字符串的内容没有关系。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
#include<string.h>
int main()
{
int b;
char c[20];
while(1)
{
printf("enter the type of your data:");
gets(c);
puts(c);
if(0==strcmp(c,"int"))
{
b=sizeof(int);
printf("%d\n\n",b);
}
else if(0==strcmp(c,"char"))
{
b=sizeof(char);
printf("%d\n\n",b);
}
else if(0==strcmp(c,"float"))
{
b=sizeof(float);
printf("%d\n\n",b);
}
else if(0==strcmp(c,"double"))
{
b=sizeof(double);
printf("%d\n\n",b);
}
else printf("输入无效!\n\n");
}
return 0;
}
//帮你写好啦
#include<string.h>
int main()
{
int b;
char c[20];
while(1)
{
printf("enter the type of your data:");
gets(c);
puts(c);
if(0==strcmp(c,"int"))
{
b=sizeof(int);
printf("%d\n\n",b);
}
else if(0==strcmp(c,"char"))
{
b=sizeof(char);
printf("%d\n\n",b);
}
else if(0==strcmp(c,"float"))
{
b=sizeof(float);
printf("%d\n\n",b);
}
else if(0==strcmp(c,"double"))
{
b=sizeof(double);
printf("%d\n\n",b);
}
else printf("输入无效!\n\n");
}
return 0;
}
//帮你写好啦
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
void main()
{
int b;
char c[20];
while(1)
{
printf("\nenter the type of your data:");
gets(c);
puts(c);
}
b=sizeof(c);
printf("\n%d",b);
}
void main()
{
int b;
char c[20];
while(1)
{
printf("\nenter the type of your data:");
gets(c);
puts(c);
}
b=sizeof(c);
printf("\n%d",b);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |