Languages [TCS Placement]: Sample Questions 6 - 7 of 131

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 6

Edit

Describe in Detail

Essay▾

What is the difference between the = symbol and == symbol?

Explanation

  • Assignment Operator (=)
  • = is an Assignment Operator in c, c ++ and other programming languages, it is Binary Operator which operates on two operands.
  • = assigns the value of right side expression՚s or variable՚s value to the left side variable
  • Example:

    x = (a + b) ;

    y = x;

  • Here, when first expression evaluates value of (a + b) . It will be assigned into x and in second expression y = x; value of variable x will be assigned into y.
  • Equal To Operator (==)
  • It is binary operator which operates on two operands.
  • == compares value on left and right side expressions- return 1 if they are equal otherwise return will be 0;
  • Example:
  1. intx, y;
  2. x=10;
  3. y=10;
  4. if(x==y)
  5. printf(“True”);
  6. else
  7. printf(“False”);
  • When expression x == y evaluates, it will return 1 and “TRUE” will be printed.

Question 7

Question

MCQ▾

What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?

Choices

Choice (4)

a.

Preprocessing error

b.

Compile-time error

c.

Runtime exception

d.

Runtime error

Answer

b.

Explanation

  • Compile time error is generated.
  • By default compiler provides zero argument constructor & copy constructor implicitly, if those are not defined explicitly.
  • However, compiler will not call default constructor (zero argument constructor) , if parameterized constructor is defined explicitly.
  • Thus creating class object without parameters will generate compile time error
  • Note: Default constructor is a constructor with no parameters (or) all parameters of the constructor are used with default arguments.
  1. #include<iostream>
  2. usingnamespacestd;
  3. classX
  4. {
  5.     private:
  6.     intx;
  7.     public:
  8.     X(intm) // Parameterized constructor
  9.     {
  10.         x =m;
  11.     }
  12. };
  13. intmain()
  14. {
  15.     Xp; // error
  16.     Xq(10); // No error
  17.     return0;
  18. }

Developed by: