为什么第二个程序应该为整数a赋予未知值? [英] Why 2nd program should give unknown value for integer a?

查看:76
本文介绍了为什么第二个程序应该为整数a赋予未知值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Main ()
{
 Char ch = 'A';                 
 ch = ch+1;
 printf ("%c", ch);
 Int a = ch;
 Printf ("%d", a);
}

输出:B66



OUTPUT:B66

Main ()
{
 Char ch = 'A';
 ch = ch+1;
 Int a = printf ("%c", ch);
 Printf ("%d", a);           
}

输出:B1



为什么第二个程序应该为整数a提供一个未知值?



我尝试过:



printf函数的返回类型是一个整数。为什么我不能将它的值存储在int中?

OUTPUT:B1

why 2nd program should give an unknown value for integer a?

What I have tried:

The return type of printf function is an integer. Why cannot i store its value in int a?

推荐答案

首先 - C / C ++区分大小写,这意味着你的代码无处可去。 。



我假设您理解为什么第一个片段打印'B66'所以我只解释第二个...



printf - 成功时 - 返回打印的字符数,在您的情况下为1,所以 a 将为1,这将给你'B1'
First of all - C/C++ is case sensitive, which means that your code goes nowhere as it is...

I assume you understand why the first snippet prints 'B66' so I explain the second one only...

printf - on success - returns the number of the characters printed, in your case 1, so a will be 1 and that will give you 'B1'


这篇关于为什么第二个程序应该为整数a赋予未知值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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