c# 情感倾向
C programming if else Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on condition statements – if else, nested if else, ladder if else, conditional operators etc.
C语言编程如果有问题,请执行以下步骤:在本节中,您将找到条件语句的C语言问题和答案-如果有,则嵌套,如果有则阶梯,有条件的运算符等。
#include <stdio.h>
void main()
{
if(!printf(""))
printf("Okkk");
else
printf("Hiii");
}
Okkk
Hiii
Error
None
Okkk
Okkk
iii
错误
没有
Okkk
#include <stdio.h>
void main()
{
int x=22;
if(x=10)
printf("TRUE");
else
printf("FALSE");
}
TRUE
FALSE
Error
None
TRUE
if(x=10)... "=" is an assignment operator, so 10 will be assigned to x and condition will be true due to if(10)..
真正
假
错误
没有
真正
if(x = 10)...“ =”是一个赋值运算符,因此由于if(10) ,x将赋给10,并且条件为true。
#include <stdio.h>
void main()
{
char val=1;
if(val--==0)
printf("TRUE");
else
printf("FALSE");
}
FALSE
Error
TRUE
None
FALSE
假
错误
真正
没有
假
#include <stdio.h>
void main()
{
float a=10.5;
printf("\n===FIRST CONDITION\n");
if(sizeof(a)==sizeof(10.5))
printf("Matched !!!");
else
printf("Not matched !!!");
printf("\n===SECOND CONDITION\n");
if(sizeof(a)==sizeof(10.5f))
printf("Matched !!!");
else
printf("Not matched !!!");
printf("\n===THIRD CONDITION\n");
if(sizeof((double)a)==sizeof(10.5))
printf("Matched !!!");
else
printf("Not matched !!!");
printf("\n===FOURTH CONDITION\n");
if(a==10.5f)
printf("Matched !!!");
else
printf("Not matched !!!");
printf("\n");
}
Not matched !!!
===SECOND CONDITION
Matched !!!
===THIRD CONDITION
Matched !!!
===FOURTH CONDITION
Matched !!!
in this program a is a float variable and value 10.5 will consider as double.
不匹配!
===第二条件
匹配!
===第三条件
匹配!
===第四条件
匹配!
在此程序中,a是一个浮点变量,值10.5将被视为double。
#include <stdio.h>
int main()
{
int a=10;
if(a==10)
{
printf("Hello...");
break;
printf("Ok");
}
else
{
printf("Hii");
}
return 0;
}
Hello...
Hello...OK
OK
Error
Error : misplaced break/ illegal break
A break statement can be used with looping and switch statements.
你好...
你好...好
好
错误
错误:错误放置的中断/非法中断
break语句可与循环和switch语句一起使用。
#include <stdio.h>
int main()
{
if( (-100 && 100)||(20 && -20) )
printf("%s","Condition is true.");
else
printf("%s","Condition is false.");
return 0;
}
Condition is true.
Condition is false.
No output
ERROR
Condition is true.
Any non zero value is treated as true for conidion.
Consider the expressions: if( (-100 && 100)||(20 && -20) )
=if( (1) || (1) )
=if(1)
条件为真。
条件为假。
无输出
错误
条件为真。
对于任何条件,任何非零值均视为true。
考虑以下表达式:if((-100 && 100)||((20 && -20))
= if((1)||(1))
=如果(1)
#include <stdio.h>
#define TRUE 1
int main()
{
if(TRUE)
printf("1");
printf("2");
else
printf("3");
printf("4");
return 0;
}
ERROR
1
12
2
ERROR : misplaced if/illegal else without matching if.
You can use only one statement within the if( )without parenthesis {...} .
错误
1个
12
2
错误:如果/错误放置,否则不匹配。
没有括号{...}的if()中只能使用一个语句。
#include <stdio.h>
int main()
{
int pn=100;
if(pn>20)
if(pn<20)
printf("Heyyyyy");
else
printf("Hiiiii");
return 0;
}
No output
Hiiiii
Heyyyyy
HeyyyyyHiiiii
Hiiiii
printf("Hiiiii"); that is written after else , is treated as else part of inner if condition if(pn<20).
无输出
i
嘿嘿
HeyyyyyHiiiii
i
printf(“ Hiiiii”); 在else后面写入的内容被视为if条件if(pn <20)的内部else部分。
1) if( a==10 ) printf("IncludeHelp");
2) if( 10==a ) printf("IncludeHelp");
3) if( a=10 ) printf("IncludeHelp");
4) if( 10=a ) printf("IncludeHelp");
3 and 4.
3 only.
4 only.
2,3 and 4.
4 only.
Consider the following expressions:
if(a==10) => if(1) => correct.
if(10==a) => if(1) => correct.
if(a=10) => if(10) => correct (10 is a non zero value).
if(10=a) => incorrect, because value of a can not assign in 10, Lvalue required error is occurred.
3和4。
仅3个。
仅4个。
2,3和4。
仅4个。
请考虑以下表达式:
if(a == 10) => if(1)=>正确。
if(10 == a) => if(1)=>正确。
if(a = 10) => if(10)=>正确(10是一个非零值)。
if(10 = a) =>错误,因为不能在10中分配a的值,所以发生了Lvalue必需的错误。
#include <stdio.h>
int main()
{
int a=10;
if(10L == a)
printf("10L");
else if(10==a)
printf("10");
else
printf("0");
return 0;
}
10.
10L.
10L10.
ERROR.
10L.
10。
10升
10L10。
错误。
10升
翻译自: https://www.includehelp.com/c-programs/c-if-else-aptitude-questions-and-answers.aspx
c# 情感倾向