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# 情感傾向