1. Tell us what do you mean by internal linking and external linking in c++?
A symbol is said to be linked internally when it can be accessed only from with-in the scope of a single translation unit. By external linking a symbol can be accessed from other translation units as well. This linkage can be controlled by using static and extern keywords.
2. Explain what do you mean by pure virtual functions in C++?
Pure virtual function is a function which doesn't have an implementation and the same needs to be implemented by the the next immediate non-abstract class. (A class will become an abstract class if there is at-least a single pure virtual function and thus pure virtual functions are used to create interfaces in c++).
3. Tell me what is an abstract class in C++?
A class with at least one pure virtual function is called as abstract class. We cannot instantiate an abstract class.
4. Do you know the purpose of the keyword volatile?
Declaring a variable volatile directs the compiler that the variable can be changed externally. Hence avoiding compiler optimization on the variable reference.
5. Tell me what is this pointer?
The ‘this' pointer is passed as a hidden argument to all nonstatic member function calls and is available as a local variable within the body of all nonstatic functions. ‘this' pointer is a constant pointer that holds the memory address of the current object. ‘this' pointer is not available in static member functions as static member functions can be called without any object (with class name).
6. Explain what is the role of protected access specifier?
If a class member is protected then it is accessible in the inherited class. However, outside the both the private and protected members are not accessible.
7. Please explain what is a reference variable in C++?
A reference variable is an alias name for the existing variable. Which mean both the variable name and reference variable point to the same memory location. Therefore updation on the original variable can be achieved using reference variable too.
8. What is an inline function in C++?
A function prefixed with the keyword inline before the function definition is called as inline function. The inline functions are faster in execution when compared to normal functions as the compiler treats inline functions as macros.
9. Tell me what do you mean by persistent and non persistent objects?
Persistent objects are the ones which we can be serialized and written to disk, or any other stream. So before stopping your application, you can serialize the object and on restart you can deserialize it. [ Drawing applications usually use serializations.]
Objects that can not be serialized are called non persistent objects. [ Usually database objects are not serialized because connection and session will not be existing when you restart the application. ]
10. Tell me the types of inheritance supported in C++?
☛ Single,
☛ Multilevel,
☛ Multiple,
☛ Hierarchical and
☛ Hybrid.
11. Explain me the storage classes names in C++?
The following are storage classes supported in C++
☛ auto,
☛ static,
☛ extern,
☛ register and
☛ mutable
12. Tell me the default standard streams in C++?
☛ cin,
☛ cout,
☛ cerr and
☛ clog.
13. Do you know what is encapsulation?
The process of binding the data and the functions acting on the data together in an entity (class) called as encapsulation.
14. Please explain the volatile and mutable keywords?
The volatile keyword informs the compiler that a variable may change without the compiler knowing it. Variables that are declared as volatile will not be cached by the compiler, and will thus always be read from memory.
The mutable keyword can be used for class member variables. Mutable variables are allowed to change from within const member functions of the class.
15. Explain void* realloc (void* ptr, size_t size)?
This function is used to change the size of memory object pointed by address ptr to the size given by size. If ptr is a null pointer, then realloc will behave like malloc(). If the ptr is an invalid pointer, then defined behaviour may occur depending the implementation. Undefined behaviour may occur if the ptr has previously been deallocated by free(), or dealloc() or ptr do not match a pointer returned by an malloc(), calloc() or realloc().
16. Explain me what is implicit conversion/coercion in c++?
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++.
17. Explain me what is virtual destructors? Why they are used?
Virtual destructors are used for the same purpose as virtual functions. When you remove an object of subclass, which is referenced by a parent class pointer, only destructor of base class will get executed. But if the destructor is defined using virtual keyword, both the destructors [ of parent and sub class ] will get invoked.
18. Do you know what is an object?
An instance of the class is called as object.
19. Tell me what is the block scope variable in C++?
A variable whose scope is applicable only within a block is said so. Also a variable in C++ can be declared anywhere within the block.
20. Tell me what is the full form of OOPS?
Object Oriented Programming System.
21. Tell us what is a storage class?
A class that specifies the life and scope of its variables and functions is called a storage class.
In C++ following the storage classes are supported: auto, static, register, extern, and mutable.
Note, however, that the keyword register was deprecated in C++11. In C++17, it was removed and reserved for future use.
22. Do you know which access specifier/s can help to achive data hiding in C++?
Private & Protected.
23. Tell me do we have a String primitive data type in C++?
No, it's a class from STL (Standard template library).
24. What is a storage class in C++?
Storage class specifies the life or scope of symbols such as variable or functions.
25. Tell me what is abstraction?
Abstraction refers to hiding the internal implementation and exhibiting only the necessary details.
26. Explain me what is meant by reference variable in C++?
In C++, reference variable allows you create an alias (second name) for an already existing variable. A reference variable can be used to access (read/write) the original data. That means, both the variable and reference variable are attached to same memory location. In effect, if you change the value of a variable using reference variable, both will get changed (because both are attached to same memory location).
27. Tell us 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);
28. Explain me what do you mean by translation unit in c++?
We organize our C++ programs into different source files (.cpp, .cxx etc). When you consider a source file, at the preprocessing stage, some extra content may get added to the source code ( for example, the contents of header files included) and some content may get removed ( for example, the part of the code in the #ifdef of #ifndef block which resolve to false/0 based on the symbols defined). This effective content is called a translation unit. In other words, a translation unit consists of
☛ Contents of source file
☛ Plus contents of files included directly or indirectly
☛ Minus source code lines ignored by any conditional pre processing directives ( the lines ignored by #ifdef,#ifndef etc)
29. Tell me when you should use virtual inheritance?
While it’s ideal to avoid virtual inheritance altogether (you should know how your class is going to be used) having a solid understanding of how virtual inheritance works is still important:
So when you have a class (class A) which inherits from 2 parents (B and C), both of which share a parent (class D), as demonstrated below:
#include <iostream>
class D {
public:
void foo() {
std::cout << "Foooooo" << std::endl;
}
};
class C: public D {
};
class B: public D {
};
class A: public B, public C {
};
int main(int argc, const char * argv[]) {
A a;
a.foo();
}
If you don’t use virtual inheritance in this case, you will get two copies of D in class A: one from B and one from C. To fix this you need to change the declarations of classes C and B to be virtual, as follows:
class C: virtual public D {
};
class B: virtual public D {
};
Opiton –lm to be used as > g++ –lm <file.cpp>
C++ does supports exception handling. try, catch & throw are keyword used for the same.
32. Explain me what do you mean by C++ access specifiers?
Access specifiers are used to define how the members (functions and variables) can be accessed outside the class. There are three access specifiers defined which are public, private, and protected
☛ private:
Members declared as private are accessible only with in the same class and they cannot be accessed outside the class they are declared.
☛ public:
Members declared as public are accessible from any where.
☛ protected:
Members declared as protected can not be accessed from outside the class except a child class. This access specifier has significance in the context of inheritance.
33. Please explain what is difference between shallow copy and deep copy? Which is default?
When you do a shallow copy, all the fields of the source object is copied to target object as it is. That means, if there is a dynamically created field in the source object, shallow copy will copy the same pointer to target object. So you will have two objects with fields that are pointing to same memory location which is not what you usually want.
In case of deep copy, instead of copying the pointer, the object itself is copied to target. In this case if you modify the target object, it will not affect the source. By default copy constructors and assignment operators do shallow copy. To make it as deep copy, you need to create a custom copy constructor and override assignment operator.
34. Explain me are you allowed to have a static const member function?
A const member function is one which isn't allowed to modify the members of the object for which it is called. A static member function is one which can't be called for a specific object.
Thus, the const modifier for a static member function is meaningless, because there is no object associated with the call.
A more detailed explanation of this reason comes from the C programming language. In C, there were no classes and member functions, so all functions were global. A member function call is translated to a global function call. Consider a member function like this:
void foo(int i);
A call like this:
obj.foo(10);
…is translated to this:
foo(&obj, 10);
This means that the member function foo has a hidden first argument of type T*:
void foo(T* const this, int i);
If a member function is const, this is of type const T* const this:
void foo(const T* const this, int i);
Static member functions don't have such a hidden argument, so there is no this pointer to be const or not.
35. Explain me which operator can be used in C++ to allocate dynamic memory?
‘new' is the operator can be used for the same.