1⟩ Is the size of character literals different in C and C++? a) Implementation defined b) Can't say c) Yes, they are different d) No, they are not different
c) Yes, they are different
“C++ Type Checking frequently Asked Questions by expert members with experience in C++ type checking. These questions and answers will help you strengthen your technical skills, prepare for the new job test and quickly revise the concepts”
c) Yes, they are different
d) both a and b
c) both 1 and 2 are true
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.
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.
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.
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
num = 10;
sqr_it(num); //type mismatch
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.
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:
using namespace std;
static int i;
static void init(int x)
i = x;
S::init(100); //initialize static variable i before creating object
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.
c) both a and b
b) f is a function taking an argument of type float and returning a integer.