问题基于C语言 [英] Question is based on C language

查看:65
本文介绍了问题基于C语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

main()

{

char x;

int y;

x = 100;

y = 125;

printf(%c\ n,x);

printf(%c \ n,y) ;

printf(%d \ n,x);

}



plzz给我输出的正确解释。



我尝试过:



在运行此代码时我得到的输出为

d

}









但是为什么????????

解决方案

因为这就是你要求的。

见这里: ASCII表 [ ^ ]



%c 说明符说将输入值视为一个字符并打印。查看表格,在Dec列下找到100 - 它是一个小写d。现在在同一列中查找125并且它是}。

所以你要求它将你的值打印为一个字符,这正是它所做的。


在查看上一个问题时,您非常需要研究C数据类型。 C,也许比你可能使用的任何其他语言都要多,会让你做蠢事,因为你要求它去做。



C写的,最初,编写操作系统。这意味着它可以做你要求它做的任何事情 - 包括混合类型。它将取决于您的编译器,让它们没有任何错误或警告。大部分时间都是标志问题,但有些事情是合理的要求。 。 。即使它们根本不是你想要做的事情。



我故意,例如,采取一串字符并将它们解释为整数。 />


SO请学习C数据类型。结果

main()
{
char x;
int y;
x=100;
y=125;
printf("%c\n",x);
printf("%c\n",y);
printf("%d\n",x);
}

plzz give me proper explanation for the Output.

What I have tried:

on running this code i am getting output as
d
}
100



but why????????

解决方案

Because that's what you asked for.
See here: ASCII table[^]

The "%c" specifier says "treat the input value as a character and print that". Look at the table, and find "100" under the "Dec" column - it's a lower case "d". Now look for "125" in the same column and it's "}".
So you asked it to print your value as a character, and that is exactly what it did.


You have, when looked at along with your previous question, a very great need to study the C data types. C, perhaps more than any other language you're likely to use, will let you do foolish things because you asked it to do them.

C was written, originally, to write operating systems. That means it is allowed to do pretty much anything you ask it to do - including mixing up types. It will, depending upon your compiler, let these go without any errors or warnings. Most of the time is flags problems for you, but some things are reasonably requests . . . even if they're not at all what you wanted to do.

I have deliberately, for example, taken a string of characters and interpreted them as integers.

SO PLEASE study C data types.


这篇关于问题基于C语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆