1. What is the difference between the keywords struct and class in C++?
Answer : By default the members of struct are public and by default the members of the class are private.
2. Explain Call by address and Call by reference
Answer : Call by address: We send address of the actual parameters instead of values. We choose this if we do want the actual parameters to be modified with formal parameters.
Call by reference: The actual parameters are received with the C++ new reference variables as formal parameters. We choose this if we do want the actual parameters to be modified with formal parameters.
3. How can we refer to the global variable if the local and the global variable names are same?
Answer : We can apply scope resolution operator (::) to the for the scope of global variable.
4. What are valid operations on pointers?
Answer : The only two permitted operations on pointers are
Comparision and Addition/Substraction
5. Which function is used to move the stream pointer for the purpose of writing data from stream?
Answer : seekp()
6. Can we create and empty class? If so what would be the size of such object.
Answer : We can create an empty class and the object size will be 1.
7. Define polymorphism?
Answer : Polymorphism means one name, multiple forms. It allows us to have more than one function with the same name in a program.It allows us to have overloading of operators so that an operation can exhibit different behaviours in different instances
8. What is iterator class?
Answer : Iterator class provides an access to the class which are inside the containers(it holds a group of objects in an organized way).
The containers include the data structure, class and abstract data type.
9. What are the types of declarations in C++?
Answer : There are so many types of declaration in C++ are :
10. What is scope resolution operator?
Answer : The Scope resolution operator(::) can be used to define the member functions of a program outside the boundary of a class and not within the class specifier.
51. What is dynamic memory allocation?
Answer : A dynamic memory allocation uses functions such as malloc() or calloc() to get memory dynamically. If these functions are used to get memory dynamically and the values returned by these function are assigned to pointer variables, such a way of allocating memory at run time is known as dynamic memory allocation.
52. What is a function?
Answer : A large program is subdivided into a number of smaller programs or subprograms. Each subprogram specifies one or more actions to be performed for the larger program. Such sub programs are called functions.
53. What is an argument?
Answer : An argument is an entity used to pass data from the calling to a called function.
54. what is the similarity between a Structure, Union and enumeration?
Answer : All of them let the programmer to define new data type.
55. Difference between array and pointer?
Answer : Array
a – Array allocates space automatically
b – It cannot be resized
c – It cannot be reassigned
d – sizeof (arrayname) gives the number of bytes occupied by the array.
a – Explicitly assigned to point to an allocated space.
b – It can be sized using realloc()
c – pointer can be reassigned.
d – sizeof (p) returns the number of bytes used to store the pointer variable p.
1. Explain the difference between reference and pointer?
Answer : a)References are less powerful than pointers. Once a reference is created, it can’t refer to other object later. Pointers provide the powerful facilities than references.
b) References are safer and easier to use than pointers. Pointers are comparatively difficult to use.
2. What are command line arguments?
Answer : The arguments which we pass to the main() function while executing the program are called as command line arguments. The parameters are always strings held in the second argument (below in args) of the function which is array of character pointers. First argument represents the count of arguments (below in count) and updated automatically by operating system.
main( int count, char *args)
3. Explain the pointer – this.
Answer : This, is the pointer variable of the compiler which always holds the current active object’s address.
4. STL stands for ?
Answer : Standard template library
5. What are static members and static functions?
Answer : Static members are created and initialized only once and shared among all the class objects.
Static functions are similar to the static variables and are associated with the class and can only access static variables of a class and can also be called using the scope resolution operator.
6. Can a function overloading depend only on passing by value and passing by reference?
Answer : No, the reason is that whether a function is called the passing a parameter as a value or by reference, it appears similar to the caller of the function.
7. How can a struct in C++ differs from a struct in C?
Answer : The differences between struct in C++ and C are listed in the following points:
In C and C++, the variables of the structures are public; however, in C, the variable cannot be declared as private or protected. On the contrary, in C++, the variables can be declared as private or protected.
In C, the concept of inheritance is not supported. In C++, the concept of inheritance is fully supported.
On declaring a struct in C, the addition of the struct keyword is must. On the contrary, there is no need of the struct keyword on declaring struct in C++.
In C, the initialization cannot be done outside the scope of a structure. However, in C++, the initialization can be done outside the scope of a structure.
In C, structures do not have direct functions or methods.
8. What are the types of STL containers?
Answer : deque
9. What is a modifier?
Answer : A modifier, also called a modifying function is a member function that changes the value of at least one data member.
In other words, an operation that modifies the state of an object.
Modifiers are also known as mutators.
10. What is the difference between array and a list?
Answer : Array is a collection of homogeneous elements while list is a collection of heterogeneous elements.
Array memory allocation is static and continuous while List memory allocation is dynamic and random.
In Array, users don’t need to keep in track of next memory allocation while In list user has to keep in track of next location where memory is allocated.