TCS Placement: Sample Questions 233 - 234 of 502

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 233

Write in Short Short Answer▾

What is the output of printf ( “% d” ) ?

Edit

Explanation

  • When we write printf ( “% d” , x will print the value of x.
  • But as here, there is nothing after % d so compiler will show in output window garbage.
  • But if the situation is
  1. main ()
  2. {
  3. int a=1, b=2, c=3;
  4. printf(“%d”);
  5. }

The output will be the value of the last variable, i.e.. 3

Question 234

Describe in Detail Essay▾

How do you instantiate a complex number?

Edit

Explanation

Different ways to assign a value to a complex number are:

  • By passing two Double values to its constructor- first value represents the real, and the second value represents imaginary part.
    • For Example: Complex c1 = new Complex (5,8) ; / ⚹ It represents (5,8) ⚹ /
    • By assigning a Byte, SByte, Intl6, UIntl6, Int32, UInt32, Int64, UInt64, Single, or Double value to a Complex object.
    • The assigned value represents real part, and imaginary part becomes 0.
    • For Example: Complex c2 = 15.8; / ⚹ It represents (15.8,0) ⚹ /
    • By casting a Decimal or BigInteger value to a Complex object.
    • For example, Complex c3 = (Complex) 12.8; / ⚹ It represents (12.8,0) ⚹ /
    • Assigning the value returned by an operator to a Complex variable.
  • For example, Complex c4c1 + c2; / ⚹ It represents (20.8,8) ⚹ /