Chapter
No-03(Operators and Expressions)
=======================================================================================
**True or False
(a)
All arithmetic operators have the same level of
precedence=False.
(b)
The modulus operators can be used only with
integers=True.
(c) The operators <=, >= and != all enjoy the
same level of priority= False
(d) During modulo division, the sign of the result is
positive, if both the operands are of the same sign=True.
(e)
In C , if the data item is zero , it is
considered false=True.
(f)
The expression!(x<=y) is same as the
expression x>y =True.
(g) A unary expression consists of only one operand
with no operators= False.
(h) Associativity is used to decide which of several
different expression is evaluated first= False.
(i)
An expression statement is terminated with a
period=False.
(j) During the evaluation of mixed expressions, an
implicit cast is generated automatically=True.
(k)
An explicit cast can be used to change the
expression=True.
(l) Parentheses can
be used to change the order of evaluation expressions=True.
**Fill in the blank.
(a) The expression containing all the integer
operands is called (arithmetic) expression.
(b)
The operator (%) cannot be used with the real
operands.
(c)
C supports as many as (6) relational operators.
(d)
An expression
that combines two or more relational expressions is termed as (logical)
expressions.
(e)
The (sizeof)
operator returns the number of bytes the operand occupied.
(f) The order of evaluation can be used changed by
using (parentheses) in an expression.
(g)
The use of
(implicit type) on a variable can change its types in the memory.
(h) (Precedence) is used to determine the order in
which different operators in an expressions are evaluated.
**Given the statement
int
a=10,b=20,c;
Determine
true or false.
(a)The statement a=+10, is valid=True.
(b)
The expression a + 4/6 * 6/2 evaluates to
11=False.
(c)
The expression b + 3/2 * 2/3 evaluates to20=True.
(d)
The statement a+=b gives the values 30 to a and
20 to b=True.
(e)
The statement
++a++; gives the value 12 to a=False.
(f)The statement a=1/b; assigns the value 0.5 to a=False.
**Declared a as int and b as float , state
whether the following statement are true or false.
(a)
The statement a=1/3+1/3+1/3;assigns the value 1
to a=False.
(b) The statement b=1.0/3.0+1.0/3.0+1.0/3.0; assigns a
value 1.0 to b=True
(c)
The statement b=1.0/3.0*3.0; gives a value 1.0 to
b=True.
(d)
The statement b=1.0/3.0+2.0/3.0;assigns a value
1.0 to b=True.
(e)
The statement a=15/10.0+3/2; assigns a value 3 to
a=False.
No
|
Expressions
|
Validity
|
|
A
|
!(5+5)>=10)
|
False
|
|
B
|
5+5==10||1+3==5
|
True
|
|
C
|
5>10||10<20&&3<5
|
True
|
|
D
|
10!=15&&!(10<20)||15>30
|
False
|
**Which of the
following arithmetic expression are valid? If valid, give the value of the
expression; otherwise give reason.
Expression
|
Validity
|
Reasons
|
|
25/3%2
|
Invalid
|
||
+9/4+5
|
Valid
|
||
7.5%3
|
Invalid
|
||
14%3+7%2
|
Valid
|
||
-14%3
|
Valid
|
||
15.25+-5.0
|
Valid
|
||
(5/3)*3+5%3
|
Valid
|
||
21%(int)4.5
|
Valid
|
**Write C
assignment statement to evaluate the following equation:
a) Solution:
|
(b) Solution:
|
#include<stdio.h>
|
#include<stdio.h>
|
#include<conio.h>
|
#include<conio.h>
|
#include<math.h>
|
#include<math.h>
|
int main()
|
Int main()
|
{
|
{
|
int r,h;
|
int m1,m2,x,y;
|
float area;
|
float T;
|
printf("Enter the value of r&h\n");
|
printf("Enter the value of
|
scanf(“%d %d",&r,&h);
|
m1,m2\n");
|
area=(3.1416*r*r+2*3.1416*r*h);
|
scanf("%f %f",&m1,&m2);
|
printf("%f",area);
|
x=(2*m1*m2*9.8);
|
return 0;
|
y=(m1+m2);
|
}
|
T=x/y;
|
printf("%f",T);
|
|
return 0;
|
|
}
|
(d) Solution:
|
|
#include<stdio.h>
|
#include<stdio.h>
|
#include<conio.h>
|
#include<conio.h>
|
#include<math.h>
|
#include<math.h>
|
#define cosx
|
int main()
|
int
main()
|
{
|
{
|
int m,h,v;
|
int
a,b,p,q,r,n,x;
|
float
Energy;
|
float side;
|
acceleration=9.8;
|
printf("Enter
the value of a,b,x\n");
|
printf("Enter
the value of
|
scanf("%d%d%d",&a,&b,&x);
|
m,h,v\n");
|
p=(a*a+b*b);
|
canf("%d%d%d",&m,&h,&v);
|
r=(2*a*b);
|
x=(9.8*h);
|
n=cos(x);
|
y=(v*v)/2;
|
side=sqrt(p-r*n);
|
Energy=m*(x+y);
|
printf("%f",side);
|
printf("%f",Energy);
|
return
0;
|
return
0;
|
}
|
}
|
**Identify unnecessary parentheses in the
following arithmetic expression.
(a) (x-(y/5)+z)%8+25
|
(b)(x-y)*p+q
|
|
(c) (m*n)+(-x/y)
|
(d)x/3*y
|
** Find the errors, if any ,in the following
assignment statement and rectify them.
(a)x=y=z=0.5,2.0,-5.75;
|
(b)m=++a*5;
|
|
(c)y=sqrt(100);
|
(d)p*=x/y;
|
|
(e)s/=5;
|
(f)a=b++-c*2;
|
**Determine the
value of each of the following logical expressions if a=5,b=10 and c=-6.
No
|
Expression
|
Value
|
|||
a
|
a>b
&& a<c
|
0
|
|||
b
|
a<b
&& a>c
|
1
|
|||
c
|
a==c
&& b>a
|
1
|
|||
d
|
b>15
&& c<0 || a>0
|
1
|
|||
**What is the output of the following program?
Solution:
|
Solution:
|
#include<stdio.h>
|
#include<stdio.h>
|
#include<conio.h>
|
#include<conio.h>
|
int main();
|
int main()
|
{
|
{
|
char x;
|
int x=100;
|
int y;
|
clrscr();
|
x=100;
|
printf("%n\n",10+x++);
|
y=125;
|
printf("%d\n",10+ ++x);
|
printf("%c\n",x);
|
return 0;
|
printf("%c\n",y);
|
}
|
printf("%d\n",x);
|
return 0;
|
Output:
|
||
}
|
110
|
||
Output: d
|
112
|
||
100
|
|||
Solution:
|
Solution:
|
||
#include<stdio.h>
|
#include<stdio.h>
|
||
#include<conio.h>
|
#include<conio.h>
|
||
int main()
|
int main()
|
||
{
|
{
|
||
int x=5,y=10,z=10;
|
int x=100,y=200;
|
||
x=y==z;
|
printf("%d",(x>y)?x:y);
|
||
printf("%d",x);
|
}
|
||
return 0;
|
|||
}
|
Output:
|
||
Output:
|
200
|
||
1
|
|||
Solution:
|
Solution:
|
||
#include<stdio.h>
|
#include<stdio.h>
|
||
#include<conio.h>
|
#include<conio.h>
|
||
int main()
|
int main()
|
||
{
|
{
|
||
unsigned x=1;
|
int x=10;
|
||
signed char y=-1;
|
if(x=20)
|
||
if(x>y)
|
printf("TRUE");
|
||
printf("x>y");
|
else
|
||
else
|
printf("FALSE");
|
||
printf("x<=y");
|
return 0;
|
||
return 0;
|
}
|
||
}
|
|||
Output:
|
Output:
|
||
No
|
TRUE
|
** What is the error in each of the following statement?
(b) if(x=<5)
|
|
printf("OK");
|
printf("Jump");
|
Output:
|
Output:
|
Error: Correct 'and' sign is '&&'
|
Error: =<
|
Correct:
<=
|
**What is the error, if any ,in the following segment?
int x=10; float y=4.25; x= y%x;
Error: Illegal use of floating point.
**What is printed when the
following is execute?
Solution:
|
Solution:
|
#include<stdio.h>
|
#include<stdio.h>
|
#include<conio.h>
|
#include<conio.h>
|
int
main()
|
int
main()
|
{
|
{
|
int m;
|
int
m=-14,n=3;
|
for(m=0;m<3;++m)
|
printf("%d\n",m/n*10);
|
printf("%d\n",(m%2)?m:m+2);
|
n=-n;
|
return 0;
|
printf("%d",m/n*10);
|
}
|
return
0;
|
Output:
|
}
|
2
|
Output:
|
1
|
-40
|
4
|
40
|
- You Can download this file as pdf by clicking below download icon-
Go ahead by honesty--->Rm
No comments:
Post a Comment