GeekInterview.com
Series: Subject: Topic:

C++ Interview Questions

Showing Questions 1 - 20 of 258 Questions
First | Prev | | Next | Last Page
Sort by: 
 | 

Fork () function

Asked By: sharad kumar sharma | Asked On: May 12th, 2012

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 ?

Answered by: Barun on: May 25th, 2012

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

What is abstraction?

Asked By: Interview Candidate | Asked On: Mar 6th, 2005

Abstraction is of the process of hiding unwanted details from the user. 

Answered by: mahender reddy on: May 21st, 2012

abstraction is the process of hiding the things which are not required and revealing the things which are required

Answered by: ravi kumar on: May 3rd, 2012

Abstraction is the process of hiding details from d external user..

What is out put of C++ code?

Asked By: ak.nextptr | Asked On: Mar 21st, 2012

Code
  1. class base
  2. {
  3.   public:
  4.          virtual void display(int i = 10)
  5.          {
  6.            cout<<"Base class display with i = "<<i<<endl;
  7.          }
  8.  
  9. };
  10.  
  11. class derived : public base
  12. {
  13.   public:
  14.           void display(int i = 20)
  15.          {
  16.            cout<<"Derived class display with i = "<< i <<endl;
  17.          }
  18.  
  19. };
  20.  
  21. int main(int argc, char *argv[])
  22. {
  23.      base *bptr = new derived;
  24.      bptr->display();
  25.        
  26.       return 0;
  27. }
  28.  

Answered by: bluesky28 on: May 15th, 2012

Derived class display with i = 20

Answered by: Shobhit Chaturvedi on: May 12th, 2012

dervie class function display

Size

Asked By: ak.nextptr | Asked On: Mar 21st, 2012

Class base { public: virtual void display() { cout

Answered by: Vipin on: May 1st, 2012

4 bytes since virtual pointer takes 4 bytes.

Function pointer

Asked By: ak.nextptr | Asked On: Mar 21st, 2012

How to assign function pointer to static function?

Answered by: cooder on: Apr 26th, 2012

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++ ?

Asked By: premtej | Asked On: Oct 12th, 2011

Answered by: FHGCVJ on: Apr 14th, 2012

..

Code
  1. int calfactorial (int x)
  2. {
  3.  int finalx = 1;
  4.  if (x==1||x==0) return 1;
  5.  for (int i = 1; i <= x; ++i) finalx = finalx * i;
  6.  return finalx;
  7. }

Answered by: Paul_Singh on: Feb 7th, 2012

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
  1. double factorial( unsigned int n )
  2. {
  3.     double result = 1;
  4.     for(unsigned int i = 1; i <=n; i++ )
  5.     {
  6.         result*=i;
  7.     }
  8.     return result;
  9. }

What do you mean by inline function?  

Asked By: Interview Candidate | Asked On: Mar 6th, 2005

 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...

Answered by: Sampada Wadkar on: Apr 9th, 2012

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
  1. CO06203

Answered by: MCBod on: Mar 31st, 2010

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?

Asked By: ak.nextptr | Asked On: Mar 21st, 2012

Answered by: supreet singh on: Mar 25th, 2012

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 ...

Command routing in mdi

Asked By: rdurgalakshmi | Asked On: Sep 15th, 2011

What is command routing in mdi

Answered by: Sandhya.Kishan on: Mar 20th, 2012

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...

Can destructor be priVATe?

Asked By: samir kumar tripathy | Asked On: Jan 21st, 2006

Answered by: NikunjSingh on: Feb 22nd, 2012

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...

Answered by: mehulgala177 on: Sep 22nd, 2011

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

Asked By: Sunil | Asked On: Nov 10th, 2011

Answered by: pavani on: Feb 18th, 2012

Where I have to write clrscr() in a CPP programme

Answered by: mujeeb3108 on: Nov 15th, 2011

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++ ?

Asked By: vikas kushwah | Asked On: Nov 5th, 2011

Answered by: NikunjSingh on: Feb 22nd, 2012

1. using normal object creation: Shape obj; 2. copy ctor: Shape obj2=obj;// or Shape obj3(obj); 3. using new operator;

Code
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Shape{
  6. public:
  7.         Shape(){cout<<"Shape..."<<endl;}
  8.         Shape(const Shape& obj)
  9.         {
  10.                 cout<<"Copy called"<<endl;
  11.         }
  12.         void* operator new(size_t size)
  13.         {
  14.                 cout<<"new...."<<endl;
  15.                 void* storage=malloc(size);
  16.                 if(NULL == storage) {
  17.                         throw "allocation fail : no free memory";
  18.                 }
  19.                 return storage;
  20.         }
  21.  
  22.         void operator delete (void*){
  23.  
  24.         }
  25. };
  26.  
  27. int main()
  28. {
  29.         Shape obj;
  30.         Shape obj2=obj;
  31.         Shape obj3(obj);
  32.         Shape* ptrShape=new Shape();
  33.         Shape* ptrShapeOver= new Shape();
  34.         return 0;
  35. }

Answered by: Isaac on: Feb 21st, 2012

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

Asked By: Sweet Titly | Asked On: Feb 4th, 2012

Answered by: nik on: Feb 22nd, 2012

Base class pointer with example

Code
  1. class A{};
  2. class B:public{};
  3. int main(){
  4. A* ptrA; //base class pointer
  5. //ptrA=new B();
  6. //or
  7. //ptrA =new A();
  8. return 0;
  9. }

Classes

Asked By: samah74 | Asked On: Oct 13th, 2010

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

Answered by: Paul_Singh on: Feb 7th, 2012

D. All of the above.

Answered by: jaroo on: Oct 2nd, 2011

The correct answwer is:

"D. all of the above"

C/c++ black screen opens and closes

Asked By: Prasad | Asked On: Sep 25th, 2011

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?

Answered by: Paul_Singh on: Feb 7th, 2012

Run it from a command prompt.

Answered by: jobin on: Oct 4th, 2011

getch();

What do you mean by inheritance?

Asked By: Interview Candidate | Asked On: Sep 8th, 2005

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.  

Answered by: PaulSingh on: Feb 7th, 2012

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...

Answered by: pooja sahu on: Feb 6th, 2012

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

Bottom-up approach

Asked By: saranya devaraj | Asked On: Sep 3rd, 2010

Why we follow top down approach in c-language and bottom up approach in c++?Explain in detail.

Answered by: Paul_Singh on: Feb 7th, 2012

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...

Answered by: abc on: Feb 5th, 2012

--> 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

Asked By: ak.nextptr | Asked On: Jan 17th, 2012

What is advantage of using constructor initialization lists?

Answered by: Paul_Singh on: Feb 7th, 2012

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...

Answered by: abc on: Feb 5th, 2012

--> 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...

Inline functions advantages

Asked By: arjunk | Asked On: Dec 6th, 2011

What is the inline function and what is the use of inline function?

Answered by: Paul_Singh on: Feb 7th, 2012

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...

Answered by: Amit on: Jan 6th, 2012

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...

What is const int *const ptr?

Asked By: papaty.priya | Asked On: Sep 4th, 2011

Answered by: Madhan on: Feb 5th, 2012

pointer to integer constant

Answered by: abc on: Feb 5th, 2012

--> a ptr that points to a const var.
--> the var cannot be changed using the ptr
--> the pointer cannot point to anyother var.

First | Prev | | Next | Last Page

 

 

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Career Counselling

 Have Career Question?

 Ask Chandra

 Ask Only Career questions.

Follow us:
 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, click "Subscribe".