Академический Документы
Профессиональный Документы
Культура Документы
a) 1 b) 2 c) 4 d) Either 1 or 2
In this case value of rightmost operator will be assigned to
the variable. In this case value of num2 will be assigned to
variable res.
Answer: b
What is the output of this C code?
#include<stdio.h>
#include< conio.h>
void main()
{ clrscr();
printf("Computer","Programming");
getch(); }
A. Computer
B. Programming
C. Computer Programming
D. None of the above
Output: Computer
You might feel that answer of this statement should be
“Programming” because comma operator always returns
rightmost operator, in case of printf statement once comma is
read then it will consider preceding things as variable or values
for format specifier.
Using Comma Operator inside Switch cases.
What is the output of this C code?
#include<stdio.h>
#include< conio.h>
void main()
{ int choice = 2 ;
switch(choice)
{ case 1,2,1: printf("\nCS");
break;
case 1,3,2: printf("\n EC");
break;
case 4,5,3: printf("\n ME");
break; }}
• A. CS B. EC C. ME D. None of the above
• Output : EC
Chaining of comparison operators in C
What is the output of this C code?
#include <stdio.h>
int main()
{
int a = 10, b = 20, c = 30;
if (c > b > a)
printf("TRUE");
else
printf("FALSE");
return 0;
}
There is no chaining of comparison operators in C
// (c > b > a) is treated as ((c > b) > a), associativity of '>'
// is left to right. Therefore the value becomes ((30 > 20) > 10)
// which becomes (1 > 10)
The output of following program is “FALSE”.
Use of pre/post Increment operator in expression
What is the output of this C code?
#include<stdio.h>
#include<conio.h>
void main()
{ int i = 0, j = 0;
j = i++ + ++i;
printf("%d\n", i);
printf("%d\n", j);}
A. 1, 1 B. 2, 2 C. 1,2 D. 2,1
Above line of code have total four operators –
Assignment Operator Post Increment Operator
Pre Increment Operator Arithmetic Operator
Now we need to arrange all the operators in the decreasing order of the Precedence –
Operator ------ Precedence Rank
Pre Increment 1 Post Increment 2
Arithmetic Operator 3 Assignment Operator 4
Now we have arranged all the operators in the decreasing order of the precedence.
Step 1 : j = i++ + 1; Step 2 : j = 1 + 1; (post-increment pending on i)
Step 3 : j = 2; (Addition) Step 4 : j = 2; (Assignment)
Step 5 : Pending increment on i will be executed Ans: B Output : 2 2
What is the output of this C code?
#include<stdio.h>
void main()
{int a,b,x=10,y=10;
a = x--;b = --y;
printf("Value of a : %d",a);
qprintf("Value of b : %d",b);
}
A. 10, 10 B. 10, 9 C. 9,10 D. 10,11
Answer B
Output: Value of a : 10Value of b : 9
What is the Output of this C code?
#include <stdio.h>
int main()
{
int x = 2, y = 0;
int z;
z = (y++, y);
printf("%d\n", z);
return 0;
}
a) 0
b) 1
c) Undefined behaviour
d) Compilation error
Answer: b
What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 2, y = 0, L;
int z;
z = y = 1, L = x && y;
printf("%d\n", L);
return 0;
}
a) 0
b) 1
c) Undefined behaviour due to order of evaluation can be
different
d) Compilation error
Answer: b
What is the output of this C code?
#include <stdio.h>
int main()
{
int y = 2;
int z = y +(y == 10);
printf("%d\n", z);
}
a) 12
b) 20
c) 2
d) Either 12 or 20
Answer: c
Which is the correct option?
Which of the following comments about the ++ operator are
correct ?
A. it is a unary operator
B. the operand can come before or after the operator
C. Both of these
Ans : C
Which of the following operators takes only integer operands?
A. +
B. *
C. /
D. %
Answer : D
What is the output of this C code?
#include <stdio.h>
int main()
{ int x = 2, y = 0;
int z = (y++) ? 2 : y == 1 && x;
printf("%d\n", z);
return 0;
}
a) 0
b) 1
c) 2
d) Undefined behaviour
Answer: b
Which is the correct option?
In a 'C'expression involving || operator, evaluation
A. Will be stopped if one of its components evaluates to false
B. Will be stopped if one of its components evaluates to true
C. Takes place from right to left
D. None of these
Ans: B
In C programming language, which of the following type of
operators have the highest precedence
A. Relational operators B. Equality operators
C. Logical operators D. Arithmetic operators
Ans:D
In C programming language, which of the following
operators has the highest precedence?
A. Unary + B. * C. >= D. = =
Ans A
Which
Coercion
is the correct option?
A. Takes place across an assignment operator
B. takes place if an operator has operands of different data
types
C. means casting
D. both (a) & (b)
Ans: D
Many programming languages support the conversion of a
value into another of a different data type. This kind of type
conversions can be implicitly or explicitly made. Implicit
conversion, which is also called coercion, is automatically
done. Coercion is the automatic conversion between
compatible types and it is done by compiler.
What is the output of this C code?
int main()
{ int i = 7;
i = i / 4;
printf("%d\n", i);
return 0; }
A. Run time error B. 1 C. 3 D. Compile time error
Answer B