Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 149 - 150 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 149

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. voidmain ()
  2. {
  3.     intk =ret (sizeof (float) );
  4.     printf ( “herevalueis %d” ++ k);
  5. }
  6. intret (intret)
  7. {
  8.     ret += 2.5;
  9.     return (ret);
  10. }

Explanation

Here value is 7

In the program

Table Shows the Program
int k = ret (sizeof (float) ) ;Firstly, the function ret () is called in which the sizeof (float) i.e.. , 4 is passed.
int ret (int ret)

{

ret += 2.5;

return (ret) ;

}

The int ret (int ret) , i.e.. , the function name and the argument name can be the same.

the sizeof (float) i.e.. . , 4 is passed after the first expression the value in ret will be 6, as ret is integer hence the value stored in ret will have implicit type conversion from float to int (which truncates the decimal part- there is no round off)

printf ( “here value is % d” ++ k) ;The ret is returned in main () it is printed after the preincrement that is 6 becomes 7.

Question 150

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Explain following operators.

Logical operators

Relational operators

Conditional operators

Explanation

Logical operators

  • Supported by C language.
  • Assume variable A holds 1 and variable B holds)
Table Showing the Logical Operators
OperatorDescriptionExample
&&
  • Called Logical AND operator.
  • If both the operands are non-zero, then the condition becomes true.
(A&&B) is false
||
  • Called Logical OR Operator.
  • If any of the two operands is non-zero, then the condition becomes true.
(A|| B) is true
!
  • Called Logical NOT Operator.
  • It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false.
! (A&&B) is true.

Rational operator:

  • Assume variable A holds 10 and variable B holds 20
Table Showing the Rational Operators
OperatorDescriptionExample
==
  • Checks if the values of two operands are equal or not.
  • If yes, then the condition becomes true.
(A == B) is not true
! =
  • Checks if the values of two operands are equal or not.
  • If the values are not equal, then the condition becomes true.
(A! = B) is true
>
  • Checks if the value of left operand is greater than the value of right operand.
  • If yes, then the condition becomes true.
(A > B) is not true
<
  • Checks if the value of left operand is less than the value of right operand.
  • If yes, then the condition becomes true.
(A < B) is true
>=
  • Checks if the value of left operand is greater than or equal to the value of right operand.
  • If yes, then the condition becomes true.
(A >= B) is not true
<=
  • Checks if the value of left operand is less than or equal to the value of right operand.
  • If yes, then the condition becomes true.
(A <= B) is true

Conditional Operators

  • Return one value if condition is true and returns another value is condition is false.
  • Also called ternary operator.
  • Syntax: (Condition? true_value: false_value) ;
  • Example: (A > 100? 0: 1) ;

If A is greater than 100,0 is returned else 1 is returned.

Equal to if else conditional statements.

Developed by: