+91 90691 39140 | +1 253 214 3115 | info@hub4tech.com | hub4tech

C++ Type checking Interview Questions and Answers

1
What are static and dynamic type checking?

Type checking is the operation on which the arguments that can only be applied for.

Static type checking performs the type checking operation before the execution of the program. To perform this operation, the arguments, expressions, variables must be given a data type.

Dynamic type checking performs the type checking operation at the time of the program execution. To perform this operation, the arguments, expressions, variables must be given a data type.

2
Explain what are associate containers?

Containers are objects that hold other objects. An associative container stores pair of values. It is typically a key-value pair. Given one value (key), we can access the other, called the mapped value. The key needs to be unique. The value associated with that key could be unique or multiple depending upon the type of associative container.

The key-value pair could be of any data type (unlike integer in case of array).
There are various types of associative containers:

Map: It is a traditional associate array, where a single value is associated with each unique pair.

Multimap : This type of associative array allows duplicate elements (value) for a given key.

3
When is dynamic checking necessary?

Dynamic checking is done at run time usually when dynamic_Cast or type casting is done. It checks if the program is strongly typed; i.e. conversions between types must be either valid.

4
Tell me What is when is dynamic checking necessary?

Dynamic checking is necessary in the following scenarios:

  • Whenever the definition of a variable is not necessary before its usage.
  • When implicit conversion of variables into other types.
  • When the program is to be compiled independently as there is no type checking at compile time.
5
What are function prototypes?

In C++ all functions must be declared before they are used. This is accomplished using function prototype. Prototypes enable complier to provide stronger type checking. When prototype is used, the compiler can find and report any illegal type conversions between the type of arguments used to call a function and the type definition of its parameters. It can also find the difference between the no of arguments used to call a function and the number of parameters in the function. Thus function prototypes help us trap bugs before they occur. In addition, they help verify that your program is working correctly by not allowing functions to be called with mismatched arguments.

A general function prototype looks like following:
return_type func_name(type param_name1, type param_name2, …,type param_nameN);
The type indicates data type. parameter names are optional in prototype.

Following program illustrates the value of function parameters:

void sqr_it(int *i); //prototype of function sqr_it
int main()
{
int num;
num = 10;
sqr_it(num); //type mismatch
return 0;
}

void sqr_it(int *i)
{
*i = *i * *i;
}
Since sqr_it() has pointer to integer as its parameter, the program throws an error when we pass an integer to it.

Copyright ©2015 Hub4Tech.com, All Rights Reserved. Hub4Tech™ is registered trademark of Hub4tech Portal Services Pvt. Ltd.
All trademarks and logos appearing on this website are the property of their respective owners.
FOLLOW US