How does a process generates child process using fork() function.The concept of it. for example: a process execute the code fork() fork() fork() total number of "child" process created is/are ?
Abstraction is of the process of hiding unwanted details from the user.
abstraction is the process of hiding the things which are not required and revealing the things which are required
Abstraction is the process of hiding details from d external user..
Code
class base { public: virtual void display(int i = 10) { cout<<"Base class display with i = "<<i<<endl; } }; class derived : public base { public: void display(int i = 20) { cout<<"Derived class display with i = "<< i <<endl; } }; int main(int argc, char *argv[]) { base *bptr = new derived; bptr->display(); return 0; }
Derived class display with i = 20
dervie class function display
Class base { public: virtual void display() { cout
4 bytes since virtual pointer takes 4 bytes.
How to assign function pointer to static function?
Using the class name. In case of non static function we need to use the this pointer.
Write a simple program for finding factorial in C++ ?
..
Code
int calfactorial (int x) { int finalx = 1; if (x==1||x==0) return 1; for (int i = 1; i <= x; ++i) finalx = finalx * i; return finalx; }
Should use the fact that in n!, n is only a positive integer. As the number increase fairly rapidly, maybe a double return is better than a signed int.
Code
double factorial( unsigned int n ) { double result = 1; for(unsigned int i = 1; i <=n; i++ ) { result*=i; } return result; }
What do you mean by inline function?
the idea behind inline functions is to insert the code of a called function at the point where the function is called. If done carefully, this can improve the application's performance in exchange for increased compile time and possibly (but not always) an increase in the size of the generated...
An Inline function is a function that is expanded in line when it is invoked. That is compiler replaces the function call with the corresponding function code.. :)
Code
CO06203
An inline function is a function where a copy of the logic is embedded in the application at each the point where it is called by the compiler. This basically allows a reduced overhead in function dereferencing
Abstract class - can we create pointer to abstract class?
yes we can create a pointer to an abstract class, which could be actually pointing to the objects of its derived classes. In this way, a container of base class pointers can be created which can also ...
What is command routing in mdi
Command routing is passing commands to its targeted objects.When a command is routed, it goes to the main frame. From the main frame, it is routed to the child frame of the active view; it is then rou...
Destrcutors can be made private to stop user from creating objects on stack. One can still create objects on stack using a static function as member function. But if intention is not to let user crea...
YESSSS destructors can be private. Infact this concept is used in Singleton design pattern. So, outsiders cannot delete object of that class. It has to b deleted from the class itself. I know...I...
What is the difference between instance and static variable
Where I have to write clrscr() in a CPP programme
Static variable: A value assigned to a static variable will be shared across all instances of the class. Instance variable: Each instance variable will hold different value that will not be share am...
What are the different way of creating object in C++ ?
1. using normal object creation: Shape obj; 2. copy ctor: Shape obj2=obj;// or Shape obj3(obj); 3. using new operator;
Code
#include <iostream> using namespace std; class Shape{ public: Shape(){cout<<"Shape..."<<endl;} Shape(const Shape& obj) { cout<<"Copy called"<<endl; } void* operator new(size_t size) { cout<<"new...."<<endl; void* storage=malloc(size); if(NULL == storage) { throw "allocation fail : no free memory"; } return storage; } void operator delete (void*){ } }; int main() { Shape obj; Shape obj2=obj; Shape obj3(obj); Shape* ptrShape=new Shape(); Shape* ptrShapeOver= new Shape(); return 0; }
1. Create on stack. i.e. ClassA varA;
2. Create on heap. i.e. ClassA *ptrA = new ClassA;
Explain base class pointer with an example
Base class pointer with example
Code
class A{}; class B:public{}; int main(){ A* ptrA; //base class pointer //ptrA=new B(); //or //ptrA =new A(); return 0; }
The copy constructor of class money is called in which of the following cases?Choose one answer. A. Money amount1;money amount2(amount 1); b. Void func(money amount);[...]money amount1;[...]func(amount1); c. Money func();[...]money amount1 = func(); d. All of the above
D. All of the above.
The correct answwer is:
"D. all of the above"
C/c++ black screen opens and closes
While executing a program in c++, it happens the black screen opens and closes automatically without displaying the output(program is correct). How to recover from this situation?
Run it from a command prompt.
getch();
What do you mean by inheritance?
Inheritance is the process of creating new classes, called derived classes, from existing classes or base classes. The derived class inherits all the capabilities of the base class, but can add embellishments and refinements of its own.
Inheritance is the ability of once class to inherit the functionality of the base class and specialise it. Typically the relationship between the derived class and the base class is an "IsA" relations...
Inheritance is a process to exess the property of exiting class which called base class and then create a new class is derived class. There are mainly 3 types.
1. Single inheritance
2. Multilevel inheritance
3. Multiple inheritance
Why we follow top down approach in c-language and bottom up approach in c++?Explain in detail.
When designing solution in an object orientated language you start by defining the lowest key players, or entities, and then begin describing how they interact. This is bottom up. In C which is a func...
--> C++ is an OOP(bottom-up approach), but it has got backward compatibility ie. accepts C prog too.(top-down approach) --> Top-down approach means in C we first go in for declaring var and func, t...
Constructor initialization lists
What is advantage of using constructor initialization lists?
For some object the initialized list is necessary because they are const or do not have default constructors. However, the main advantage is that if you construct the object in the constructor body th...
--> initializer list is used with constructor when any const datas are used in a class. --> bcoz, as we known const var should be initialized while declaring. --> the class gets memory allocatio...
What is the inline function and what is the use of inline function?
The inline keyword is a request to the compiler that you want the function body to be inserted into the compiled code as opposed to a function call. Typically used for functions that are called very o...
Inline function: they are same as Normal function but compiler treat them diffrently. When we call a inline function compiler will replace the call by inline function body (It depends upon how you hav...
pointer to integer constant
--> a ptr that points to a const var.
--> the var cannot be changed using the ptr
--> the pointer cannot point to anyother var.
The number of Child Processes Created would be
2^(No. of Fork() functions called)
So in the example given it would be
2^3 = 8 Child Processes