C++

Explain the variable assignment in the declaration

int *(*p[10])(char *, char *);

It is an array of function pointers that returns an integer pointer. Each function has two arguments which in turn are pointers to character type variable. p[0], p[1],….., p[9] are function pointers.

return type : integer pointer.

p[10] : array of function pointers

char * : arguments passed to the function

Program: Example program to explain function pointers.

#include <stdio.h>

#include <stdlib.h>

int *(*p[10])(char *, char *);

//average function which returns pointer to

Can main() be overridden ?

In any application, there can be only one main function. In c++, main is not a member of any class. There is no chance of overriding

What is the difference between macro and inline()?

1. Inline follows strict parameter type checking, macros do not. 2. Macros are always expanded by preprocessor, whereas compiler may or may not replace the inline definitions.

What is memory leaking in c++ ?

When a class uses dynamically allocated memory internally, all sorts of problems arise. If not properly used or handled, they can lead to memory leaks & corrupts Data Structures. A memory leak is the situation that occurs when dynamically allocated memory is lost to the program. Char * p;

p= new char[10000];

…..

p= new char[5000];

Initially, 10000 bytes are dynamically allocated & the the address of those bytes is stored in p. later 5000 bytes are dynamically allocated & the address is stored in p. However, the original 10000 bytes’ve not been returned to the system using delete [] operator. Memory leak actually More >

What is importance of const. pointer in copy constructor?

Because otherwise you will pass the object to copy as an argument of copy constructor as pass by value which by definition creates a copy and so on… an infinite call chain

Why can’t we overload the sizeof, :?, :: ., .* operators in c++

The restriction is for safety. For example if we overload. Operator then we can’t access member in normal way for that we have to use ->.

Is there any way to write a class such that no class can be inherited from it. Please include code

Simple, make all constructors of the class private.

What is virtual class and friend class?

Friend classes are used when two or more classes are designed to work together and virtual base class aids in multiple inheritance.

What is the difference between class and structure?

1:By default, the members of structures are public while that for class is private

2: structures doesn’t provide something like data hiding which is provided by the classes

3: structures contains only data while class bind both data and member functions

We can overload assignment operator as a normal function.But we can not overload assignment operator as friend function why?

If the operation modifies the state of the class object, it operates on, it must be a member function, not a friend fucntionThus all operator such as =, *=, +=, etc are naturally defined as member functions not friend functions Conversely, if the operator does not modify any of its operands, but needs only a representation of the object, it does not have to be a member function and often less confusing. This is the reason why binary operators are often implemented as friend functions such as + , *, -, etc..