仓库操作员能力矩阵
C programming Operators Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on various Operators like Arithmetic, Assignment, Compound Assignment, Relation Operators etc.
C编程运算符能力问题:在本节中,您将找到有关算术,赋值,复合赋值,关系运算符等各种运算符的C能力问题。
C编程操作员能力倾向问题列表 (List of C programming Operators Aptitude Questions and Answers)
#include <stdio.h>
void main()
{
printf("value is = %d",(10++));
}
Correct Answer - 4
Error : L-value required
++/-- operator works on variables only.
#include <stdio.h>
void main()
{
const char var='A';
++var;
printf("%c",var);
}
Correct Answer - 3
Error : increment of read-only variable 'var'.
++/-- operator works on variables only, we can not change the value of a const.
#include <stdio.h>
void main()
{
int x=10;
x+=(x++)+(++x)+x;
printf("%d",x);
}
Correct Answer - 2
45
1) expand the expression : x=x+(x++)+(++x)+x;
2) due to pre increment ++x , x will be 11 for this expression.
3) after executing expression x will be 44.
4) finally x will be 45 due to post increment (x++).
Note: the output of pre and post increment based operators may not same on all the compilers, in GCC Linux compiler output will be 46 and in TurboC output will be 45.
正确答案-2
45
1)扩展表达式: x = x +(x ++)+(++ x)+ x;
2)由于预递增++ x ,因此该表达式的x将为11。
3)执行表达式后, x将为44。
4)最后,由于后期增量( x ++ ), x将为45。
注意:在所有编译器上,基于前后增量运算符的输出可能并不相同,在GCC Linux编译器中输出为46,在TurboC输出中为45。
#include <stdio.h>
void main()
{
int a=10,b=2,x=0;
x=a+b*a+10/2*a;
printf("value is =%d",x);
}