Operators and Expressions II-65
3.
void main()
{
int x=2,y=3,z;
x+y=z;
printf("z=%d",z);
}
Bug: Variable must be at left side
4.
void main()
{
clrscr();
printf("%d %d",+2,2+);
}
Bug: 2+ is not allowed
Relational operators
5.
void main()
{
clrsr();
printf(" %d",20==15);
printf(" %d",10>=15);
printf(" %d",9<8);
printf(" %d", 'A'=='a');
}
Bug: Replace clrsr with clrscr() and answer of all conditional statements
would be 0
6.
void main()
{
char a=4,b=16,m,n,o;
clrscr();
m=a<2;
n=b>3;
o=a!=b;
M03_ITL-ESL4791_02_SE_C03.indd 65 12/22/2012 5:00:09 PM
II-66 Programming Concepts
printf(" %c",m);
printf(" %c",n);
printf(" %c",o);
getche();
}
Bug: Replace c by d in all printf() statements. Answer will be
0
1
1
7.
void main()
{
int x=2,z;
clrscr();
z=x=>2;
printf("%d",z);
}
Bug: => operator is invalid
Logical operators and conditional operator
8.
void main()
{
char p=90;
int a;
clrscr();
a=(p>=65 && p<=90 ? 1 : 0);
printf("Y :%c",a);
getche();
}
Bug: Replace %c with %d in printf() and answer would be Y:1
M03_ITL-ESL4791_02_SE_C03.indd 66 12/22/2012 5:00:09 PM
Operators and Expressions II-67
9.
void main()
{
int a,b,c;
clrscr();
a=4;
b=2;
c=(a<<b && b>>1 );
printf(" c=%c",c);
getche();
}
Bug: Replace %c by %d in printf() and answer would be c =1
M03_ITL-ESL4791_02_SE_C03.indd 67 12/22/2012 5:00:09 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset