0% found this document useful (0 votes)
93 views12 pages

4.1 State Whether The Following Statements Are True or False

This document contains questions and answers related to C programming expressions and operators. It covers topics like precedence of operators, unary vs binary expressions, logical vs relational vs arithmetic expressions, implicit type casting, and evaluating expressions. Multiple choice and true/false questions are asked about the output of code snippets involving expressions and basic C syntax.

Uploaded by

Easteak Ahamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views12 pages

4.1 State Whether The Following Statements Are True or False

This document contains questions and answers related to C programming expressions and operators. It covers topics like precedence of operators, unary vs binary expressions, logical vs relational vs arithmetic expressions, implicit type casting, and evaluating expressions. Multiple choice and true/false questions are asked about the output of code snippets involving expressions and basic C syntax.

Uploaded by

Easteak Ahamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

4.

1 State whether the following statements are true or false:

(a) The expression !(x<=y) is same as the expression x>y.


Ans. True
(b) A unary expression consists of only one operand with no operators.
Ans. False
(c) All arithmetic operators have the same level of precedence.
Ans. False
(d) An expression statement is terminated with a period.
Ans. False
(e) The operators <=, >= and != all enjoy the same level of priority.
Ans. False
(f) The modulus operators can be used only with integers.
Ans. True
(g) In C , if the data item is zero , it is considered false.
Ans. True
(h) During the evaluation of mixed expressions, an implicit cast is generated
automatically.
Ans. True
(i) An expression statement is terminated with a period.
Ans. False
(j) Associativity is used to decide which of several different expression is
evaluated first.
Ans. False
(k) Parentheses can be used to change the order of evaluation expressions.
Ans. True
(l) During modulo division, the sign of the result is positive, if both the operands
are
of the same sign.
Ans. True

4.2 Fill in the blanks with appropriate words.


a. The expression containing all the integer operands is called arithmetic
expression.
b. C supports as many as six relational operators.
c. The size of operator returns the number of bytes the operand occupies.
d. Precedence is used to determine the order in which different operators in an
expression evaluated.
e. An expression that combines two or more relational expression is termed as
logical expression.
f. The use of implicit type on a variable can change its type in the memory.
g. The order of evaluation can be changed by using parentheses in an expression.
h. The operator % cannot be used with real operands.
i. and operation have the highest and lowest levels of precedence respectively.
j. <= is a relational operator while && is a logical operator.
k. A division operation involving integer operands truncates the resultant
value. The situation can be avoided by using
l. The result of a relational expression is either true or false.
4.3: Given the statement int a=10, b=20, c; Determine true or
false.

(a)The statement a=+10, is valid.


Ans. True
(b) The expression a + 4/6 * 6/2 evaluates to 11.
Ans. False
(c) The expression b + 3/2 * 2/3 evaluates to20.
Ans. True
(d) The statement a+=b gives the values 30 to a and 20 to b.
Ans. True
(e) The statement ++a++; gives the value 12 to a.
Ans. False
(f)The statement a=1/b; assigns the value 0.5 to a.
Ans. False

3.4: 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.


Ans. False
(b)The statement b=1.0/3.0+1.0/3.0+1.0/3.0; assgns a value 1.0 to b.
Ans. True
(c)The statement b=1.0/3.0*3.0; gives a value 1.0 to b.
Ans. True
(d)The statement b=1.0/3.0+2.0/3.0;assigns a value 1.0 to b.
Ans. True
(e) The statement a=15/10.0+3/2; assigns a value 3 to a.
Ans. False

4.4 Declared a as int and b a float, state whether the following statements are
true or false.
a. The statement a=1/3+1/3+1/3;assigns the value 1 to a.
Ans :False
b. The statement b=1.0/3.0+1.0/3.0+1.0/3.0;assigns a value 1.0 to b.
Ans: True
c. The statement b=1.0/3.0*3.0 gives a value 1.0 to b.
Ans:True
d. The statement b=1.0/3.0+2.0/3.0 assigns a value 1.0 to b;
Ans: True
e. The statement a=15/10.0+3/2;assigns a value of 3 to a.
Ans: False

4.5
a. !(5+5>=10)
Ans: False
b.5+5 = =10 || 1+3 ==5;
Ans: True
c.5>10||10<20 &&3<5
Ans: True
d.10!=15 && !(10<20) ||15>30
Ans: False

4.6 Which of the following arithmetic expression are valid ? If valid, giving the
value of the expression.
a.25/3%2
Ans: Invalid
b.+9/4+5
Ans: Valid
c.7.5%3
Ans: Invalid
d.14%3 +7%2
Ans: Valid
e.-14%3
Ans: Valid
f.15.25+-5.2
Ans: Valid
g.(5/3)*3+5%3
Ans: Valid
h.21%(int)4.5
Ans: Valid
4.7 Writing C assignment statements to evaluate the following equations:
a.
#include<stdio.h>
int main()
{
int r,h;
float area;
printf(“r=”);
scanf(“%d ”,&r);
printf(“h=”);
scanf(“%d”,&h);
area=3.1416*r*r+2*3.1416*r*h;
printf(“Area= %f”,area);
return 0;
}

b.
#include<stdio.h>
int main()
{
int m1,m2;
float g,torque;
printf(“m1=”);
scanf(“%d ”,&m1);
printf(“m2=”);
scanf(“%d”,&m2);
printf(“g=”);
scanf(“%f”,&g);
torque=(2*m1*m2*g)/(m1+m2);
printf(“Torque=%f”,torque);
return 0;
}

c.
#include<stdio.h>
int main()
{
int a,b,p,q,r,n,x;
float side;
printf(“Enter the value of a,b,x\n”);
scanf(“%d%d%d”,&a,&b,&x);
p=(a*a+b*b);
r=(2*a*b);
n=cos(x);
side=sqrt(p-r*n);
printf(“%f”,side);
return 0;

d.
#include<stdio.h>
int main()
{
int mass,acceleration,height,velocity;
float energy;
printf(“mass=”);
scanf(“%d”,&mass);
printf(“acceleration=”);
scanf(“%d”,&acceleration);
printf(“height=”);
scanf(“%d”,&height);
printf(“velocity=”);
scanf(“%d”,&velocity);
energy=mass*(acceleration*height+pow(velocity,2)/2);
printf(“%f”,energy);
return 0;
}

4.8 Identifying unnecessary parentheses in the fallowing arithmetic expression.


a.((x-(y/5)+z)%8)+25
Ans:(x-(y/5)+z)%8+25
b.((x-y)*p)+q
Ans:(x-y)*p+q
c.(m*n)+(-x/y)
Ans:(m*n)+(-x/y)
d.x/(3*y)
Ans:x/3*y
4.9 Determine the value of each of the following logical expression if a=5,b=10
and c=-6
a. a>b &&a<c
Ans:0
b.a<b &&a>c
Ans:1
c.a==c ||b>0
Ans:1
d.b>15&&c<0||a>0
Ans:1
e.(a/2.0==0.0 &&b/2.0!=0.0||c<0.0
Ans:1
4.10 Output of the following program
main()
{
char x;
int y;
x =100;
y =125;
printf(“%c\n”,x);
printf(“%c\n”,y);
printf(“%d\n”,x);
}
Output: d
}
100

4.11 Output of the following program


main()
{
int x=100;
printf(“%d/n”,10 + x++;
printf(“%d/n”,10 + x++);
}
Output: 110
112
4.12 Output of the following program
main()
{
int x=5,y=10,z=10;
x =y==z;
printf(“%d”,x);
}
Output:5

4.13 Output of the following program


main()
{
int x=100,y=200;
printf(“%d”,(x>y)?x:y);
}
Output:200

4.14 Output of the following program


main ()
{
unsigned x=1;
signed char y=-1;
if(x>y)
printf(“x>y”);
else
printf(“x<=y”);
}
Output:x<=y
4.15 Output of the following program
main()
{
int x=10;
if(x=20) printf(“True”);
else printf(“False”);
}
Output: True

4.16 15 Output of the following program


#include<stdio.h>
Int main()
{
for (m=0; m<3;++m);
printf(“%d/n”,(m%2) ?m:m+2);
}
Output: Undeclared

4.17 Output of the following program


#include<stdio.h>
int main()
{
int m=-14, n=3;
printf(“%d\n”,m/n*10);
n=-n;
printf(“%d\ n”,m/n*10);
}
Output:-40
40

You might also like