想要关注以下c程序的建议。 [英] Want a suggestion for following c program.
问题描述
大家好,这是我的第二个问题而且我不理睬我,但我没有得到它所以请帮助我。
在下面的程序中我知道输出但是我很困惑已完成。
计划1
Hello guys this is my second question and it is quit foolish of me, but I am not getting it so please help me.
In the following program I know the output but I am confused how it is done.
Program 1
#include<stdio.h>
#include<conio.h>
main()
{
int x=2;
if(x=3)
{
printf("%d",x++);
}
else
{
printf("%d",--x);
}
getch();
}
以下程序的输出 3 但它是怎么来的,我不知道得不到。
计划2
The output of the following program is 3 but how it comes, I don''t get it.
Program 2
#include<stdio.h>
#include<conio.h>
int main()
{
int x=01234;
printf("The result is %d",x);
return 0;
getch();
}
以下程序的输出 668 并且没有得到它也好。
所以请给我一些提示。
谢谢大家......:)
The Output of the following program is 668 and don''t get it too.
So please give me some hint.
Thanks guys...:)
推荐答案
在程序1中,x = 3赋值隐藏在if语句中。程序员常常使用赋值(=)运算符代替等号(==)运算符。
在程序2中,当你指定一个变量x的值你使用八进制形式(当数字文字以0开头时它是一个八进制数字)
In the program 1 the x=3 assignment is hidden inside the if statement. It is a common mistake by the programmers to use assignment (=) operator in place of equal (==) operator.
In the program 2, when you assign a value to variable x you use an octal form (when a numeric literal begins with 0 it is an octal number)
这实际上是一个糟糕的问题。出于什么目的编写代码?您是否在Code项目中测试成员?听program1,如果条件没有比较。即,看你的代码
This is realy a bad question. For what purpose the code is write? Are you test members in Code project? Listen program1, there is no comparison in if condition. ie, watch your code
if( x = 3 )
。 Actualy这里将值3分配给x。没有比较。
不要在代码项目中发布这类问题。您可以调试代码并确保发生的事情。
. Actualy here value 3 is assigned to x. no comparison is done.
Don''t post this type of question in code project. You can debug the code and ensure what happend.
在程序1中,x = 3赋值隐藏在if语句中。程序员常常使用赋值(=)运算符代替等号(==)运算符。
In the program 1 the x=3 assignment is hidden inside the if statement. It is a common mistake by the programmers to use assignment (=) operator in place of equal (==) operator.
这篇关于想要关注以下c程序的建议。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!