C++ Type Checking Interview Preparation Guide

Refine your C++ Type Checking interview skills with our 27 critical questions. These questions will test your expertise and readiness for any C++ Type Checking interview scenario. Ideal for candidates of all levels, this collection is a must-have for your study plan. Dont miss out on our free PDF download, containing all 27 questions to help you succeed in your C++ Type Checking interview. Its an invaluable tool for reinforcing your knowledge and building confidence.
Tweet Share WhatsApp

27 C++ Type Checking Questions and Answers:

1 :: Can you explain static function?

Static member functions are used to maintain a single copy of a class member function across various objects of the class. Static member functions can be called either by itself, independent of any object, by using class name and :: (scope resolution operator) or in connection with an object.

Restrictions on static member functions are:

1. They can directly refer to other static members of the class.
2. Static member functions do not have this pointer.
3. Static member function can not be virtual.

Though there are several restrictions on static member functions, one good use of them is to initialize private static data members of a class before any object is created.

Consider following example:
#include <iostream>
using namespace std;
class S
{
static int i;
public:
static void init(int x)
{
i = x;
}
void show()
{
cout <<i;
}
};

int S::i;
int main()
{
S::init(100); //initialize static variable i before creating object
S x;
x.show();
return 0;
}
Download PDFRead All C++ Type Checking Questions

2 :: Do you know 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.

3 :: 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.

4 :: What is static type checking?

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.

5 :: What is dynamic type checking?

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.
Download PDFRead All C++ Type Checking Questions

6 :: 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.

7 :: How many characters are specified in the ASCII scheme?
a) 64
b) 128
c) 256
d) none of the mentioned?

b) 128

8 :: Select the right option.
Given the variables p, q are of char type and r, s, t are of int type
1. t = (r * s) / (r + s);
2. t = (p * q) / (r + s);
a) 1 is true but 2 is false
b) 1 is false and 2 is true
c) both 1 and 2 are true
d) both 1 and 2 are false

c) both 1 and 2 are true

9 :: Which of the following belongs to the set of character types?
a) char
b) wchar_t
c) only a
d) both a and b

d) both a and b

10 :: What will be the output of this program?

#include <iostream>
using namespace std;
int main()
{
char c = 74;
cout << c;
return 0;
}
a) A
b) N
c) J
d) I

c) J
Download PDFRead All C++ Type Checking Questions