CHAPTER-3
Review Questions:
3.1: True or False.
(a) All arithmetic operators have the same level of precedence. Ans. False
(b) The modulus operators can be used only with integers. Ans. True
(c) The operators <=, >= and != all enjoy the same level of priority. Ans. False
(d) During modulo division, the sign of the result is positive, if both the operands are
of the same sign. Ans. True
(e) In C , if the data item is zero , it is considered false. Ans. True
(f) The expression!(x<=y) is same as the expression x>y. Ans. True
(g) A unary expression consists of only one operand with no operators. Ans. False
(h) Associativity is used to decide which of several different expression is evaluated first. Ans. False
(i) An expression statement is terminated with a period. Ans. False
(j) During the evaluation of mixed expressions, an implicit cast is generated automatically. Ans. True
(k) An explicit cast can be used to change the expression. Ans. True
(l) Parentheses can be used to change the order of evaluation expressions. Ans. True
3.2: 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.
3.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
3.5 Which of the following expression are true?
(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
3.6 Which of the following arithmetic expression are valid? If valid, give the value of the expression; otherwise give reason.
(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.0 Ans. Valid
(g) (5/3)*3+5%3 Ans. Valid
(h) 21%(int)4.5 Ans. Valid
3.7:Write C assignment statement to evaluate the following equation:
(a)
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int r,h;
float area;
clrscr();
printf("Enter the value of r,h\n");
scanf(“%d %d",&r,&h);
area=(3.1416*r*r+2*3.1416*r*h);
printf("%f",area);
getch();
}
(d)
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int m,h,v;
float Energy;
clrscr();
acceleration=9.8;
printf("Enter the value of m,h,v\n");
scanf("%d%d%d",&m,&h,&v);
x=(9.8*h);
y=(v*v)/2;
Energy=m*(x+y);
printf("%f",Energy);
getch();
}
(b)
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int m1,m2,x,y;
float T;
clrscr();
printf("Enter the value of m1,m2\n");
scanf("%f %f",&m1,&m2);
x=(2*m1*m2*9.8);
y=(m1+m2);
T=x/y;
printf("%f",T);
getch();
}
(c)
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define cosx
void main()
{
int a,b,p,q,r,n,x;
float side;
clrscr();
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);
getch();
}
3.8:Indentyfy unnecessary parantheses in the following artimatic expression.
(a)(x-(y/5)+z)%8+25
(b)(x-y)*p+q
(c)(m*n)+(-x/y)
(d)x/3*y
3.9: 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;
3.10: Determine the value of each of the following logical expressions if a=5,b=10 and c=-6.
(a) a>b && a<c Value:0
(b) a<b && a>c Value:1
(c) a==c && b>a Value:1
(d) b>15 && c<0 || a>o Value:1
3.11:What is the out put of the following program?
Solution:
#include<stdio.h>
#include<conio.h>
void main();
{
/*...characters......*/
char x;
int y;
x=100;
y=125;
printf("%c\n",x);
printf("%c\n",y);
printf("%d\n",x);
getch();
}
Output: d
100
3.12:Find the output of the following program?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
/*....increment......*/
int x=100;
clrscr();
printf("%n\n",10+x++);
printf("%d\n",10+ ++x);
getch();
}
Output:
110
112
3.13:What is printed by the following program?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int x=5,y=10,z=10;
clrscr();
x=y==z;
printf("%d",x);
getch();
}
Output: 1
314:What is the output of the following program ?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int x=100,y=200;
clrscr();
printf("%d",(x>y)?x:y);
}
Output: 200
3.15:What is the output of the following program?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
unsigned x=1;
signed char y=-1;
clrscr();
if(x>y)
printf("x>y");
else
printf("x<=y");
getch();
}
Output:
No
3.16:What is the output of the following program? Explain the output.
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int x=10;
clrscr();
if(x=20)
printf("TRUE");
else
printf("FALSE");
getch();
}
Output:
TRUE
3.17: What is the error in each of the following statement?
(a) if(m==1 & n!=0)
printf("OK");
Output:
Error: Correct 'and' sign is '&&'
(b) if(x=<5)
printf("Jump");
Output:
Error: =<
Correct: <=
3.18: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.
3.19:What is printed when the following is execute?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int m;
clrscr();
for(m=0;m<3;++m)
printf("%d\n",(m%2)?m:m+2);
getch();
}
Output:
2
1
4
3.20:What is the output of the following statement?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int m=-14,n=3;
clrscr();
printf("%d\n",m/n*10);
n=-n;
printf("%d",m/n*10);
getch();
}
Output:
-40
40
3.11 output is
ReplyDeleted
}
100
bt why i cant understand.pls hlp..
Lol . after 3 years here is a answer.
Deletewhen you print a character by value it take it as a ASCII value.
100 is ASCII value of d and 125 is ASCII value of }.
3.3 (a)The statement a=+ 10, is valid. Ans.false because '+'and '10' between spaces so (A) is false
ReplyDelete3.1 d is False....the sign of first operand or divend is given in the output
ReplyDeleteExplanation of a ans for 3.15?????
ReplyDeleteplz ans asap.
3.6 a or e
ReplyDeletereason give pls
can anyone please explain 3.4(b)
ReplyDeleteTnks
ReplyDeleteHelp ful
ReplyDeleteHelp ful
ReplyDeleteIF YOU WANT TO START YOUR C/C++ Programming go through this link
ReplyDeletehttp://www.alphaplutonic.blogspot.com
Thanks
ReplyDeletein true or false the and for option no d will be false
ReplyDelete3.10 please help me .
ReplyDeletePara
DeleteTq it's very helpful
ReplyDeleteazure online course
ReplyDeletejava online course
salesforce online course
hadoop online course
Data Science online course
linux online course
etl testing online course
web methods online course
business analyst training
Answers of 3.8, 3.8?
ReplyDeletewhere is the answer of 3.8 and 3.9?
ReplyDelete