Monday, September 24, 2018

C++ Interview Questions

In how many ways we can initialize an int variable in C++?
In c++, variables can be initialized in two ways, the traditional C++ initialization using “=” operator and second using the constructor notation.
Traditional C++ initilization
  • int i = 10;
variable i will get initialized to 10.
Using C++ constructor notation
  • int i(10);
Implicit conversions are performed when a type (say T) is used in a context where a compatible type (Say F) is expected so that the type T will be promoted to type F.
short a = 2000 + 20;
In the above example, variable a will get automatically promoted from short to int. This is called implicit conversion/coercion in c++.

No comments:

Post a Comment