Q: 1 Which of the following operators takes only integer operand?
+
/
*
None of these
[ Option D ]
The operators + (addition), * (multiplication), and / (division) can work with both integer and floating-point operands. There is no restriction that these operators must take only integer operands.
Q: 2 Conditional operator also known as
Bitwise operator
Condition checking operator
Ternary operator
Special purpose operator
[ Option C ]
The conditional operator is also called the ternary operator because it works with three operands.
Syntax:
(condition) ? True Part : False Part;
#include <stdio.h>
int main()
{
int a,p,q,min;
printf("Enter A Number : ");
scanf("%d",&a);
a%2==0?printf("%d is Even",a):printf("%d is Odd",a);
printf("
Enter Two Number : ");
scanf("%d%d",&p,&q);
min=p<q?p:q;
printf("Minimum : %d",min);
return 0;
}
OUTPUT
Enter A Number : 89
89 is Odd
Enter Two Number : 63 58
Minimum : 58
Q: 3 The two operator && and || are
Logical operator
Relational operator
Arithmetic operator
Equality operator
[ Option A ]
The operators && (AND) and || (OR) are called logical operators. They are used to combine multiple conditions in decision-making statements like if, while, or for.
#include <stdio.h>
int main()
{
int a, b;
printf("Enter two Numbers: ");
scanf("%d%d",&a,&b);
if (a>0 && b>0)
{
printf("Both Numbers are Positive.
");
}
if (a<0 || b<0)
{
printf("At least One Number is Negative.
");
}
if (!(a == b))
{
printf("The Numbers are Not Equal.");
}
return 0;
}
OUTPUT
Enter two Numbers: -87 56
At least One Number is Negative.
The Numbers are Not Equal.
Q: 4 Which operator from the following has the lowest priority?
Assignment operator
Conditional operator
Arithmetic operator
Unary operator
[ Option A ]
The higher order precedence of given operators is:
Q: 5 What is result of -17%5?
2
-2
3
-3
[ Option B ]
The modulus operator (%) is used to find the remainder after division of two integers. The sign of the result of % depends on the sign of the left operand (dividend). So, so -17%5 results in -2.
Note:
For solving % operator, there is no direct approach so it can be solved by using the equation, a%b=a-(a/b)*b and sign of remainder is determined by sign of first operand left to % symbol (dividend).
Now, the given expression is −17%5. Here a is -17 and b is 5.
a%b=a-(a/b)*b
-17%5 = -17-(-17/5)*5
-17%5 = -17-(-3*5)
-17%5 = -17+15
-17%5 = -2
Q: 6 What is output of below code
void main()
{
int a=5, b=17, c=8, d;
d=(a=c,b+=a,c=a+b+c);
printf("%d %d %d %d", d, a, b, c);
}
41 8 4 41
41 8 25 41
13 7 41 44
Compile time error
[ Option B ]
The comma operator evaluates expressions from left to right, and the value of the entire expression is the value of the last expression.
| Expression Evaluated | Explanation | a | b | c | d |
|---|---|---|---|---|---|
| — | Initial values. | 5 | 17 | 8 | — |
| a = c | Assign value of c i.e., 8 to a. | 8 | 17 | 8 | — |
| b += a | b = b + a. so, 17 + 8 = 25 | 8 | 25 | 8 | — |
| c = a + b + c | c = 8 + 25 + 8 = 41 | 8 | 25 | 41 | — |
| d = (Last Value) | d gets value of last expression i.e., 41 | 8 | 25 | 41 | 41 |
Q: 7 The result of statement printf("%d",(17*2)%(int)5.5); is?
2
4
0
Compile time error
[ Option B ]
In the given statement printf("%d",(17*2)%(int)5.5); first, 17*2 gives 34. Then type casting is applied, where (int)5.5 converts the floating-point value 5.5 into the integer value 5 by removing the decimal part.
After this, the expression becomes 34%5. The modulus operator returns the remainder after division, and when 34 is divided by 5, the remainder is 4. Therefore, the value printed by printf() is 4.
Q: 8 What will be value of i and k after execution the following code.
void main()
{
int i,j,k;
j=5;
i=2;
i=2*j/2;
k=2*(j/i);
}
i=5, k=5
i=4, k=4
i=4, k=5
i=5, k=2
[ Option D ]
| EXPRESSION | CALCULATION | RESULT |
|---|---|---|
| j = 5 | — | j = 5 |
| i = 2 | — | i = 2 |
| i = 2 * j / 2 | 2 * 5 / 2 | 10 / 2 = 5 |
| k = 2 * (j / i) | 2 * (5 / 5) | 2 * 1 = 2 |
Q: 9 The result of the statement printf("%d",(10/3)*3+!5%3); is?
Expression syntax error
11
9
Run time error
[ Option C ]
| Expression | Explanation | Result |
|---|---|---|
| 10/3 | Integer division, decimal part discarded. | 3 |
| (10/3)*3 | Multiply result by 3 i.e., 3*3 | 9 |
| !5 | Logical NOT of non-zero value. | 0 |
| !5%3 | Modulus of 0 with 3. | 0 |
| (10/3)*3+!5%3 | Add both parts i.e., 9+0 | 9 |
Q: 10 After execution the following statement what will be the value of variable a.
void main()
{
float a,b;
a=2;
b=3;
a*=b*=+28.5;
printf("%f",a);
}
Compile time error.
171
171.000000
-171.000000
[ Option C ]
The float variables a and b are first initialized with the values 2 and 3, respectively. The expression b *= +28.5 is evaluated first, which is equivalent to b = 3*28.5, resulting in b = 85.5. Next, the expression a *= b is evaluated, which is equivalent to a = 2*85.5, resulting in a = 171.
Finally, when printf("%f",a); is executed, the float value of a is printed in standard floating-point format as 171.000000.
Q: 11 What is equivalent expression for a%b in C?
a+(a/b)*b
a-(a/b)*b
b-(a/b)*b
No such type of expression exists
[ Option B ]
In C language, the modulus operation a % b is equivalent to the expression a-(a/b)*b, where integer division is used.
Q: 12 What is the result of the following expression?
(5<8)&&(3>1)
1
0
Undefined
None of the above
[ Option A ]
This expression uses the logical AND (&&) operator in C. The logical AND returns 1 (true) if both conditions are true, otherwise it returns 0 (false).
In given expression (5<8)&&(3>1), first, the relational expression 5<8 is evaluated, which is true and returns 1. Next, the relational expression 3>1 is also evaluated, which is true and returns 1. Since both conditions are true, the logical AND operation 1&&1 results in 1.
Q: 13 Which of the following comments about the ++ operator is correct?
It cannot be applied to an expression
It is a unary operator
The operand can come before or after the operator
All of the above
[ Option D ]
The operator ++ is called increment operator and it is used to increase the value of a variable by 1. It has several properties:
Q: 14 What is result of -17%-5?
Can’t find remainder of negative number
-2
3
2
[ Option B ]
The modulus operator (%) is used to find the remainder after division of two integers. The sign of the result of % depends on the sign of the left operand (dividend). So, so -17%-5 results in -2.
Note:
For solving % operator, there is no direct approach so it can be solved by using the equation, a%b=a-(a/b)*b and sign of remainder is determined by sign of first operand left to % symbol (dividend).
Now, the given expression is −17%-5. Here a is -17 and b is -5.
a%b=a-(a/b)*b
-17%-5 = -17-(-17/-5)*-5
-17%-5 = -17-(3*-5)
-17%-5 = -17+15
-17%-5 = -2
Q: 15 What will be the output of the following program?
void main()
{
int a=2;
int b=10;
int c;
c=!((a<2)&&(b>2));
printf("%d",c);
}
1
0
-1
2
[ Option A ]
In C language, relational operators are used to compare values, and they return 1 for true and 0 for false.
The result of logical AND (&&) is true only if both conditions are true and logical NOT (!) reverses the result i.e., true becomes false, false becomes true.
| EXPRESSION | EVALUATION | RESULT |
|---|---|---|
| a=2 | Initially value assigned. | 2 |
| b=10 | Initially value assigned. | 10 |
| a<2 | 2<2 | 0 |
| b>2 | 10>2 | 1 |
| (a<2)&&(b>2) | 0&&1 | 0 |
| !((a<2)&&(b>2)) | !0 | 1 |
| c | Final value. | 1 |
Q: 16 What is output after executing the code.
void main()
{
int i=10;
i = !i>14;
printf("%d", i);
}
1
0
10
14
[ Option B ]
Initially, the variable i is initialized to 10. The expression i = !i > 14; have operator Logical Not (!) and greater than (>). According to operator precedence, the logical NOT operator (!) has higher precedence than the relational operator greater than (>). Therefore, the expression is interpreted as i = (!i) > 14;
Since i is 10 (a non-zero value), !i becomes 0, because the logical NOT of any non-zero value is 0. Now the expression becomes i = 0 > 14; The comparison 0 > 14 is false, and in C, false is represented as 0. Therefore, the final value stored in i is 0.
Q: 17 The symbol that helps the user to command the computer to do a certain mathematical or logical manipulations is called ___________.
Operand
Function
Operator
Keyword
[ Option C ]
An operator is a special symbol that tells the computer to perform a specific mathematical or logical operation.
For example, symbols like +, -, *, / are arithmetic operators used for calculations, while symbols like ==, >, and < are logical or relational operators used for comparisons.
Q: 18 In an expression involving || operator, evaluation
(1) Will be stopped if one of its components evaluates to false.
(2) Will be stopped if one of its components evaluates to true.
(3) Takes place from right to left.
(4) Takes place from left to right.
(1) and (2)
(1) and (3)
(2) and (3)
(2) and (4)
[ Option D ]
The logical OR operator || evaluates expressions using short-circuit evaluation. This means:
Q: 19 What is result of -17/5?
2
-2
3
None of these
[ Option D ]
In C language, when both operands are integers, the division operator (/) performs integer division. Integer division discards the decimal part and keeps only the whole number. So, -17/5 = -3
Q: 20 Which of the following is not a bitwise operator?
<<
.
&
>>
[ Option B ]
Bitwise operators are used to perform operations directly on the binary representations (bits) of integer numbers. The common bitwise operator are:
| Operator | Description |
|---|---|
| & | Bitwise AND |
| | | Bitwise OR |
| ^ | Bitwise XOR |
| ~ | Bitwise NOT |
| << | Left Shift |
| >> | Right Shift |
The symbol "." (dot) is not a bitwise operator. It is commonly used as a member access operator in programming languages like C, C++, and Java for accessing fields or methods of a structure or object.
Q: 21 Initially the value of variable a is 4, after evaluating the expression a*=5+2; the value of variable a is?
22
11
28
Compile time error
[ Option C ]
Initially, the variable a has a value of 4. The statement a *= 5+2; uses a compound assignment operator *= which multiplies the current value of a by the result of the expression on the right-hand side.
According to operator precedence rules, the addition 5+2 is evaluated first, giving 7. Then, the multiplication is performed, a = a*7 = 4*7 = 28. Therefore, after executing the statement, the value of a becomes 28.
Q: 22 What will be the value of x,y,z after the execution of the following program?
void main()
{
int x,y,z;
y=2;
x=2;
x=2*(y++);
z=2*(++y);
z=x,y;
printf("%d %d %d",x,y,z);
}
4 4 8
4 4 2
2 4 8
4 4 4
[ Option D ]
| Statement | Explanation | x | y | z |
|---|---|---|---|---|
| y=2 | Initially, assign 2 to y. | – | 2 | – |
| x=2 | Initially, assign 2 to x. | 2 | 2 | – |
| x=2*(y++) | Use current value y i.e., 2, then y becomes 3. | 4 | 3 | – |
| z=2*(++y) | First Increment y to 4, then use it. | 4 | 4 | 8 |
| z=x,y | Comma operator z=x first, then y. | 4 | 4 | 4 |
Q: 23 Consider the following group
(1) - , +
(2) <, > , <= , >=
(3) / , *
(4) ++ , --
(5) ! , ~
(6) && , ||
Arrange these according to higher order precedence.
(1) (2) (3) (4) (5) (6)
(4) (5) (6) (3) (1) (2)
(4) (5) (3) (1) (2) (6)
(5) (4) (3) (2) (1) (6)
[ Option C ]
When multiple operators come together in an expression then operator precedence determines the order in which operators are evaluated in an expression.
Q: 24 What is the output? A system where integer occupy 4 bytes memory.
#include<stdio.h>
int main()
{
int a=5,b=8,c;
c=sizeof(a=10,b=20,a+b+2.5);
printf("%d %d %d",a,b,c);
}
5 8 8
5 8 4
10 20 4
10 20 8
[ Option A ]
In the given C program, the expression inside the sizeof operator is sizeof(a=10,b=20,a+b+2.5). Here, the comma operator is used. With the comma operator, all expressions are evaluated from left to right, but the value and type of the entire expression are determined only by the last expression.
Therefore, although a=10 and b=20 appear inside sizeof, they are not actually executed, because sizeof (compile time operator) does not evaluate expressions, it only determines the size of the resulting data type.
The last expression is a+b+2.5. Since 2.5 is a double, the entire expression becomes of type double. On the given system, the size of double is 8 bytes, so c = 8. Because sizeof does not evaluate assignments, the values of a and b remain unchanged as 5 and 8.
REMEMBER:
Q: 25 Which of the expression correctly defines the statement?
Check whether the values of 3 variables age1, age2, and age3 are equal to each other.
age1 = age2 = age3
age1 == age2 and age2 == age3
age1 != age2 != age3
age1 = age2 and age2 = age3
[ Option B ]
To check if the values of three variables age1, age2, and age3 are equal in C programming (and most languages), you use the equality operator == (Equal to) along with logical AND (&&) to combine multiple conditions.
Remember, the operator = is called assignment operator which is used for assign the value to the left-hand side operand (variable).
Q: 26 What is the difference between && and & operator in C?
No difference; both are logical AND
&& is logical AND, & is bitwise AND
&& is a syntax error
& is a syntax error
[ Option B ]
Q: 27 What would be the value of variable res after execution the below code.
void main()
{
int res;
float a,b;
a=104.85;
b=41.19;
res=a+b;
}
145
146
145.01
146.01
[ Option B ]
The two floating-point variables a and b are assigned the values 104.85 and 41.19, respectively. Their sum is calculated as a+b = 104.85+41.19 = 146.04.
This sum is then assigned to the variable res, which is declared as an integer. In C, when a floating-point value is assigned to an integer variable, the decimal part is truncated. As a result, the value stored in res becomes 146.
Q: 28 Given b=101 and c=10, what is the value of ‘a’ after executing of the expression a=b-=c*=3?
41
71
87
Invalid expression
[ Option B ]
The expression a=b-=c*=3 is evaluated from right to left because compound assignment operators associate right-to-left. Given that b = 101 and c = 10, the operation begins with the innermost expression c*=3, which multiplies c by 3 and updates it to 30. Next, the expression b-=c subtracts the new value of c (30) from b, updating b to 71. The result of the expression b -= c is this updated value of b, so the value assigned to a becomes 71.
Q: 29 #include<stdio.h>
int main()
{
int i=5,j=10,k=15;
printf(”%d ”,sizeof(k/=i+j));
printf(”%d”,k);
return 0;
}
Assume size of an integer as 4 bytes. What is the output of above program?
2 1
4 1
4 15
More than one of the above
[ Option C ]
The first printf statement uses sizeof(k/=i+j), where k/=i+j is an expression of type int. The sizeof operator determines the size of the operands type at compile time without evaluating the expression itself, so no side effect occurs, no assignment modifies k, which remains 15.
Given that the size of an int is 4 bytes, the first printf outputs 4. The second printf then outputs the unchanged value of k, which is 15. Thus, the complete output is 4 15.
Q: 30 In C programming, the operator ‘&’ is used to represent
Logical AND
Bitwise AND
Logical OR
Bitwise OR
[ Option B ]
In C language:
Q: 31 The associativity of comma operator is from?
Right to left
Left to right
Both (a) and (b)
Neither (a) nor (b)
[ Option B ]
The comma operator (,) in C has left-to-right associativity, meaning expressions separated by commas are evaluated from left to right, and the value of the entire expression is the value of the rightmost expression.
int a;
a=(15,30,45);
printf("%d",a);
The output is 45 because evaluation goes: 15 → 30 → 45, and the final value is taken.
Q: 32 Relational operators are accessed by ALU, which gives maximum of __________ possible output.
0
1
2
3
[ Option C ]
Relational operators perform comparisons like equal to, not equal to, less than, greater than, etc. The Arithmetic Logic Unit (ALU) evaluates these comparisons and outputs one of two possible values, typically, 0 (false) or 1 (true).
Thus, the maximum number of outputs the ALU can give for relational operations is 2, representing true or false conditions.
Q: 33 What is output after executing the code.
void main()
{
int i=0, j=1, k=2, m;
m = i++ || j++ || k++;
printf("%d %d %d %d", m, i, j, k);
}
1122
1123
0122
None of these
[ Option A ]
Initially, the variables are initialized as i = 0, j = 1, and k = 2. The expression m = i++ || j++ || k++; uses the logical OR (||) operator, which follows short-circuit evaluation. This means the expression is evaluated from left to right, and the moment it encounters a true (non-zero) value, the remaining expressions are not evaluated.
| EXPRESSION PART | RETURNED VALUE | VARIABLE AFTER EVALUATION | EFFECT |
|---|---|---|---|
| i++ | 0 | i = 1 | Result is false, so check next operand. |
| j++ | 1 | j = 2 | The OR becomes true. So, stop evaluation. |
| k++ | Not evaluated. | k = 2 | Short-circuit, because j++ was true. |
| Final m value. | 1 | — | The OR expression result is true. |
Q: 34 Find the odd one considering C language.
a=a+1;
a+=1;
a++;
a=+1;
[ Option D ]
The first three statements, a=a+1;, a+=1;, and a++;, all increment the value of a by 1.
However, a=+1; does not increment a. It simply assigns the value +1 to a, replacing its previous value.
Q: 35 In C sizeof is a/an?
Operator
Variable
Keyword
None of these
[ Option A ]
In C, the sizeof is not a variable or a keyword, instead, it is a compile-time operator that returns the size of its operand (variable, expression, or pointer).
Q: 36 The associativity of which of the following operators is Left to Right, in C.
Unary operator
Logical NOT
Array Element Access
Addressof
[ Option C ]
In C language, most binary operators follow left-to-right associativity, while most unary operators follow right-to-left associativity. Among the options given, the array element access operator ([]) is a postfix operator, and postfix operators always associate left to right. This means when multiple array subscripts or postfix expressions appear together, they are evaluated from left to right.
| OPERATOR | NAME | ASSOCIATIVITY | PRECEDENCE |
|---|---|---|---|
| ( ) | Parenthesis (Function Call) | Left to Right L→R | Highest Precedence than Other Operator 1st |
| [ ] | Square Bracket (Array Subscript) | ||
| . | Member Selection Via Name (Structure Operator) | ||
| → | Member Selection via Pointer (Structure Operator) | ||
| ++ | Postfix Increment | ||
| -- | Postfix Decrement |
Q: 37 Which of the following is not a logical operator?
Check
AND
OR
NOT
[ Option A ]
Logical operators are used in programming and algorithms to perform decision-making based on true or false of conditions.
| LOGICAL OPERATOR | MEANING |
|---|---|
| AND | True if both conditions are true. |
| OR | True if at least one condition is true. |
| NOT | Reverses the logical state, true becomes false, false becomes true. |
Q: 38 What is the result after executing of the following code if ‘a’ is 10, ‘b’ is 5 and ‘c’ is 10?
if((a>b) && (a<=c))
a = a+1;
else
c = c+1;
a = 10, c = 10
a = 11, c = 10
a = 10, c = 11
a = 11, c = 11
[ Option B ]
Initially, the variables are a = 10, b = 5, and c = 10. The if statement checks the condition (a > b) && (a <= c). Evaluating step by step: a > b is 10 > 5, which is true, and a <= c is 10 <= 10, which is also true. Since both parts of the condition are true, the && operator makes the whole condition true. Therefore, the code inside the if block executes, which is a = a + 1, so a becomes 11. The else block does not execute, so c remains 10.
Q: 39 What value will print after executing the below program
void main()
{
float a=2.3;
a+=.2;
printf("%f",a);
}
2.5
2.500000
4
Expression syntax error
[ Option B ]
Here the variable a is initialized with the value 2.3. The statement a+=.2; is a compound assignment operator, which means a=a+0.2, so the new value of a becomes 2.5.
When printf("%f", a); is executed, the %f format specifier prints floating-point values with six digits after the decimal point by default. Therefore, the output displayed is 2.500000
Q: 40 Which operator has the highest priority
||
&&
=
,
[ Option B ]
The operator precedence determines the order in which operators are evaluated in an expression.
The logical AND operator && has higher precedence than logical OR (||), assignment (=), and the comma operator (,). This means that in an expression containing these operators, && will be evaluated first, followed by ||, then =, and finally ,.
Q: 41 Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1?
rem = 3.14 % 2.1;
rem = modf(3.14, 2.1);
rem = fmod(3.14, 2.1);
Remainder cannot be obtaining in floating point.
[ Option C ]
In C, the % (modulus) operator is used to find the remainder of division, but it works only with integers, not floating-point numbers.
To calculate the remainder when dividing floating-point numbers like 3.14 and 2.1, we need to use the fmod() function, which is defined in the math.h header file.
#include <stdio.h>
#include <math.h>
int main()
{
float rem;
rem = fmod(3.14,2.1);
printf("Remainder : %f",rem);
return 0;
}
OUTPUT
Remainder : 1.040000
Q: 42 Which operator has the highest priority
+
*
!
%
[ Option C ]
The logical NOT operator ! is a unary operator, and unary operators have higher precedence than binary operators like *, %, or +. This means expressions with ! are evaluated before multiplication, modulus, or addition when combined in a single statement.
Q: 43 Which of following is not a valid operator in C language?
&
~
#
!
[ Option C ]
Operators are symbols that perform operations on variables and values. Among the given options, & is bitwise AND operator, ~ is bitwise NOT operator, ! is logical NOT operator.
The # is not an operator, it is used in C as a preprocessor directive symbol like #include or #define but cannot perform any operation.
Q: 44 Which of the following statement is wrong?
a=155;
b=‘a’*5;
d/=14;
a*b=4*5;
[ Option D ]
| STATEMENT | EXPLANATION |
|---|---|
| a=155; | Valid. Simple assignment. |
| b='a'*5; | Valid. The 'a' is a character constant, treated as an integer. Multiplication allowed. |
| d /=14; | Valid. Compound assignment operator. Equivalent to d=d/14;. |
| a*b=4*5; | Invalid. Left side of assignment must be a variable, not an expression. |
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.