1.
OBJECTIVE TYPE QUESTION
F 1. Fill in the blanks:
a. Operators
and operands together form a/an expression.
b.
The arithmetic operator Modulus
is used only with integer variable.
c.
The relational expression result in either true or
false.
d.
In C, true is evaluated as 1 and
false is evaluate as 0.
e.
The logical operator Minus(-)
is a unary operator.
f.
The Assignment operator evaluates the expression on the
right hand side and assign it to a variable.
g.
The Equal mark operator assigns a value to a
variable.
h.
The Operator is the part at the left of an
assignment.
i.
The Sizeof operator accepts one parameter and
returns the size in bytes.
j.
The conditional operator evaluates an expression
on returning a value after Question Mark if that
expression is true.
1. 2. Write True or False.
a.
The modulus operator has the highest precedence
in arithmetic operators. True
b.
|| is a logical operator. True
c.
The NOT operator has highest precedence in
logical operators. False
d.
Relational operators are used to compare two
expressions. True
e.
The relational operator has highest precedence
than the logical operators. True
f.
The comma operator is used to separate two or
more expression. True
g.
Increment and decrement operators are unary. True
h.
The conditional operators are used to separate
two or more expressions that are included where only one expression is expected.
False
i.
The sizeof () operator accepts one Parameter. True
j.
The exponent operator available in C. True
1. 3. Choose the Correct options:
a. Arithmetic Operators are
i)
Binary
i)
Unary
ii)
Both
iii)
None of these
b. Part of the left assignment operator
i)
Lval
ii)
Lvalue
ii)
leftval
iii)
None of these
c. *= is a /an
i) Arithmetic
Operator
ii) Conditional Operator
iii) Compound assignment Operators
iv) None of these
d.
==is a / an
i)
Arithmetic Operator
ii)
Relational
Operator
iii)
Compound assignment Operators
iv)
None of these
e. && is a / an
i)
Logical Operator
ii)
Conditional Operator
iii)
Compound assignment Operators
iv)
None of these
f. If a is an integer, then a =20%3 will return
the value
i)
6
ii)
2
iii)
3
iv)
1
g.The expression 10/3 will return the value
i)
1
ii)
10
iii)
1
iv)
3.3333
h.
If a=15, then a+=7 will return the value
i)
20
ii)
22
iii)
8
iv)
7
i.
If x =9, then ---x will return the value
i)
10
ii)
9
iii)
8
iv)
7
j.The expression a=(b=5,b+3) will return the
value
i)
5
ii)
8
iii)
7
iv)
6
Click to top Click To Top
DESCRIPTIVE TYPE QUESTION
1.
1. Short answer questions:
a)
Name any six types of operators included
in C.
AnsArithmetic Operators, Logical Operators, Increment and
Decrement Operators, special Operators, Relational Operators, and Relational
Operators are the six operators included in C.
b)
Explain the working of the modulus
operators by an example.
AnsModulus is the operation that gives the remainder of a
division of two Values.
For example, if we evaluate the following C statement
a = 10 % 3;
Here variable a will contain the value 1,
since 1 is the remainder we get after dividing 10 /3.
Note: Modulus operation requires integer values;
otherwise, we may get an error.
c)
Mention any four relational operators.
Ans == (equal to), > (greater than), > (less than), !=
(not equal to) are the four rational operators.
d)
Give the priority in logical operators.
Ans && (AND)
operator, || (OR) operator, ! (NOT) operators are the priority in logical
operator.
e)
What is the assignment operator used for?
Ans An Assignment
Operators are used for assigning a value to a variable.
f)
What are the increment and decrement
operators used for?
Ans An increment operator
is used to increase the value stored in a variable by one. Whereas, decrement
operator decreases the value stored in a variable by one.
g)
Do the following two statements perform
the same task?
Ans Yes
h)
If the value of a is 7, what will be the
value of a+=10;?
Ans If the
value of a= 7. Then,
a+=10 (a+=a+1)
a+=a+10
a+=7+10
a+=17
i)
If the value of a is 6, what will be the
output of the statement b=a++;?
Ans if a is 6 and b=a++ then the value of b is 6+1=7
j)
Are both the following statements the same?
a=5/3
a=5/3.0
Ans No, because a=5/3 is an integer number whereas,
a=5/3.0 is a real number.
1.
2. Long answer questions:
a)
Write short notes on logical operators.
Explain the concept by giving suitable examples.
Ans In C language
there are three logical operators. The && (AND), || (OR) and !
(NOT) operator.
They are used to combine two or more conditions or
relational expression, and even constants and result is either True (1) or
False (0).
The concepts of logical operators is simple. They allow
a program to make a decision based on multiple conditions. Each operand is
considered a conditions that can be evaluate to a true(1) or false(0)
value. Then the value of the condition is used to determine the overall value
of the operator grouping. For example
The && operator perform the Boolean
Operation AND. It is a binary operator which required two operands. This
operator gives the net result of true(1). If both operand are true, otherwise
false(0). For example (5==5) && (3>6) in this expression
first condition is true(1) and second is false(0) so the output
we get is 0.
The || Operand perform the Boolean operation OR. It is also binary
operator. This operator gives the net result of True(1) if at least one operand
is True(1), otherwise false(0). For example.
(5==5)||(3>6) in this expression the first condition
is true(1) and the second is false(0) so the output we get is 1.
The ! Operator perform the NOT Boolean operation. NOT
operator negates the value of the condition. If the condition is false(0) then
it becomes true(10), if true(1) it becomes false(0). It is a unary operator.
For example: !(5==5) in this expression the condition is
true(1) but the output we get is 0 i.e False.
b)
Write the following using the relational
operators:
i) 2x is equal to 5y
ii) 3a is not equal to 5b
iii) C-7 is less than or equal to 3y
iv) a is equal to or greater than b
v) a is less than b
vi) x+3 is greater than y+5
Ans: i. 2x==5y
ii.
3a!=5b
iii. 3y=c-7<=3y
iv. b=a>=b
v.
a<b
vi.
X+5>y+5
c)
Write down the following using logical
operators:
i)
x is equal to 4 and y is equal to 5
ii)
a is equal to b or a is equal to c
iii)
x is not equal to 100
iv)
x is greater than 3 and y is less than 5
v)
a is greater than or equal to 90 and a is less
than or equal to 100.
Ans: i. (x==4)&&(y==5)
ii. (a==b)||(a<c)
iii. !(x==100)
iv.
(x>3)&&(y<5)
v.
(a>90)&&(a<=100)
d)
What is the different between the
following two programing codes?
i. Int a,b;
a=7;
b=a++;
printf(“%d%d”,a,b);
ii. Int a,b
a=7;
b=++a;
printf(“%d%d”,a,b
Ans: i)
a=7;
b=a++; // b contain 7, a contains 8
in the above statement the increment operator is used as a suffix
(as in a++), the outer expression is evaluated with the current value of a and
then the value stored in a is increased by 1.
ii) a=7;
b=++a // b contain 8, a contains 8
in the above statement the increment operator is used as prefix(as
in ++a), the value stored in a is increased by 1 and this value is used in the
outer expression.
e)
What is a comma operator? Explain with
the help of an example.
Ans: The comma operator is used to separate two or
more expressions that include where only one expression is expected. For
example : a=(b=3,b+2);
In the above
expression the first value assign is 3 to b, and then b+2 is evaluated, which
is 5 and then assign it to the variable a. So, at the end, variable a would
contain the value 5 and variable b would contain the value 3.
f)
A C program has the following declaration and initial
assignments:
int i =2, j = 5;
float
x = 0.25, y = -0.1; char c = ‘a’, d =
‘b’;
Determine the value of each of the
following expressions. Use the values initially assigned for each variable.
i.
++i vi. x >=0
ii.
i++ vii. x<yy
iii.
–j viii.
C==100
iv.
++x ix. D==98
v.
I<= -j x.
!(i<=j)
Ans: i) int i= 2, ++i: i=3
ii) i++,i=2
iii) –j:j=-5
g) A C program has the following
declaration and initial assignments:
int
i=8, j=5,k;
float
x=0.25, y=-0.1,z;
char
a,b,c= ‘c’, d= ‘d’;
Determine
the value for the following assignment expression. Use the values initially
assigned for each variable.
i. z=k=x
ii. y-=x
iii. I+=(j-2)
iv. z=x+y
v. k=z=x
vi. k=(j==5)?i:j
vii. i-=2
viii. y+=x
ix. a=(c<d>?c:d
x. i%=j
xi. i/=j
xii. k=c
Ans:
h) Explain the conditional
operator by taking an example.
Ans: The conditional operator evaluates
an expression and returns the value after ‘?’ if the expression is true, and
the value after ‘:’ if the expression evaluated is false.
It is also called as ternary
operator.
Syntax: (condition? True_value:
false_value);
Example: (A >100 ? 0 : 1);
#include<stidio.h>
Int main()
{
Int x=1,y;
y=(x==1?2:0);
Printf(“x value is %d\n”,x);
Printf(“y value is %d”,y);
}
i) Explain the precedence of arithmetic
operators with the help of an example.
Ans: Operator precedence determines
the grouping of terms in expression and decides how an expression is evaluated.
Certain operators have higher precedence than others; for example, x=7 +3*2;
here x is assigned 13, not 20 because operator * has higher precedence than
+, so it first gets multiplied with 3*2 and then adds in to 7.
NOTE: The multiplication
operator has higher precedence than the addition operator.
Click to top
Click To Top
0 Comments