GeekInterview.com
Series: Subject: Topic:

C++ Interview Questions

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

What are the disadvantages of c++?

Asked By: premadona | Asked On: Aug 3rd, 2007

Answered by: Sanjay on: Apr 20th, 2013

Java is Beautiful Language , & who said that in java you don't required any logical aptitude.. now slowly c++ will be disappear

Answered by: burraganesh on: Dec 7th, 2008

C++ has plenty of features than C, so a lot of syntax needs to be know by the programmer. Well when we need more, we should learn more.Another disadvantage is that C++ is not suitable for embedded co...

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: reddy- on: Apr 10th, 2013

Overriding function default argument takes more precedence ,Hence based class default argument 10 will be initialized to i.So i value holds 10 will be printed for this call with derived count statement.

Answered by: panreth on: Aug 23rd, 2012

Answer is : "derived class display with i=10"

What is the difference between an object and a class?

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

 classes and objects are separate but related concepts. Every object belongs to a class and every class contains one or more related objects.  Ø      a class is static. All of the attributes of a class are fixed before, during, and after the execution of a program....

Answered by: jaya jaswani on: Feb 2nd, 2013

A class is a user defined data type which is used to declare objects and define the methods and functions to use the object.

An object is an instance of a class. it can be generated according to our needs whenever we want to use that. but classes once declared cant destroyed.

Answered by: Abhishek on: Dec 26th, 2012

Both are hardly interrelated. Object 1. Basic runtime entities in object oriented environment. 2. Objects belong to only one class. ...

What is the difference between class and structure?

Asked By: Interview Candidate | Asked On: Jul 5th, 2005

Structure: initially (in c) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public. Class: class is a...

Star Read Best Answer

Editorial / Best Answer

Answered by: sumitv

View all answers by sumitv

Member Since Sep-2008 | Answered On : Sep 4th, 2008

Structure does support inheritance.

try out the following code.

#include<iostream>

using namespace std;

struct Base
{
    int A;
};

struct Derived:public Base
{
    int B;
    void display();
};

void Derived::display()
{
    cout<<endl<<"A = "<<A<<endl;
}

int main()
{
    Derived D;
    D.A = 111;
    D.display();
    getchar();
    return 0;
}

Try out private and protected inheritance as well. It works. :)

Regards,
Sumit

Answered by: prasad on: Dec 27th, 2012

inline can be used in structures ...it is possible to work

Answered by: yogish on: Aug 5th, 2011

structure support multiple inheritence also try this code"cpp struct stud1 { int x; float y; stud1(int x,float y) { this->x = x; this->y = y; } }; struct stud2:public stu...

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: mukrram ur rahman on: Dec 9th, 2012

Abstraction exactly involve the process of involving relevant things while ignoring the irrelevant things.

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

Matrix operation using operator overloading

Asked By: shakthisangi | Asked On: Jan 15th, 2010

Write a program for four atrithmetic operations in matrix using operator overloading.

Answered by: JoolsL on: Nov 19th, 2012

In both the above answers the op overloads should be using a const ref as input. You should have a (private) ctor that makes the matrix from the data, and should use RVO in the return.

Answered by: binoy on: Aug 23rd, 2012

Code
  1. #include<iostream.h>
  2. #include<conio.h>
  3. class matrix
  4. {
  5.   private:long m[5][5];
  6.   int row;int col;
  7.   public:void getdata();
  8.   int operator ==(matrix);
  9.   matrix operator+(matrix);
  10.   matrix operator-(matrix);
  11.   friend ostream & operator << (ostream &,matrix &);
  12. };
  13. /* function to check whether the order of matrix are same or not */
  14. int matrix::operator==(matrix cm)
  15. {
  16.   if(row==cm.row && col==cm.col)
  17.   {
  18.     return 1;
  19.   }
  20.   return 0;
  21. }
  22. /* function to read data for matrix*/
  23. void matrix::getdata()
  24. {
  25.   cout<<"enter the number of rows
  26. ";
  27.   cin>>row;
  28.   cout<<"enter the number of columns
  29. ";
  30.   cin>>col;
  31.   cout<<"enter the elements of the matrix
  32. ";
  33.   for(int i=0;i<row;i++)
  34.   {
  35.     for(int j=0;j<col;j++)
  36.     {
  37.        cin>>m[i][j];
  38.     }
  39.   }
  40. }
  41. /* function to add two matrix */
  42. matrix matrix::operator+(matrix am)
  43. {
  44.   matrix temp;
  45.   for(int i=0;i<row;i++)
  46.   {
  47.     for(int j=0;j<col;j++)
  48.     {
  49.       temp.m[i][j]=m[i][j]+am.m[i][j];
  50.     }
  51.     temp.row=row;
  52.     temp.col=col;
  53.   }
  54.   return temp;
  55. }
  56. /* function to subtract two matrix */
  57. matrix matrix::operator-(matrix sm)
  58. {
  59.   matrix temp;
  60.   for(int i=0;i<row;i++)
  61.   {
  62.     for(int j=0;j<col;j++)
  63.     {
  64.       temp.m[i][j]=m[i][j]-sm.m[i][j];
  65.     }
  66.     temp.row=row;
  67.     temp.col=col;
  68.   }
  69.   return temp;
  70. }
  71. /* function to display the contents of the matrix */
  72. ostream & operator <<(ostream &fout,matrix &d)
  73. {
  74.   for(int i=0;i<d.col;i++)
  75.   {
  76.     for(int j=0;j<d.col;j++)
  77.     {
  78.       fout<<d.m[i][j];
  79.       cout<<" ";
  80.     }
  81.     cout<<endl;
  82.   }
  83. return fout;
  84. }
  85. /* main function */
  86. void main()
  87. {
  88.   matrix m1,m2,m3,m4;
  89.   clrscr();
  90.   m1.getdata();
  91.   m2.getdata();
  92.   if(m1==m2)
  93.   {
  94.     m3=m1+m2;
  95.     m4=m1-m2;
  96.     cout<<"Addition of matrices
  97. ";
  98.     cout<<"the result is
  99. ";
  100.     cout<<m3;
  101.     cout<<"subtraction of matrices
  102. ";
  103.     cout<<"The result is
  104. ";
  105.     cout<<m4;
  106.   }
  107.   else
  108.   {
  109.     cout<<"order of the input matrices is not identical
  110. ";
  111.   }
  112.   getch();
  113. }

Can time delay be generated in C through loops? If yes,how?

Asked By: Tapas Mallick | Asked On: Aug 19th, 2012

Answered by: k.raghu06 on: Oct 30th, 2012

Yes, delay can be produced using the loops. but the delay cannt be same on all processors. That means, each processor shall have its own speed of executing an instruction. hence the execution speed in...

How is static variable stored in the memory?( if there are 2 functions in a file,and the static variable name is same (ex var) in both the function. How is it keep seperately in the memory).

Asked By: Subhajit | Asked On: Mar 15th, 2006

Answered by: Bishoy on: Oct 20th, 2012

Local variables are stored in stack - each method have a stack frame (a fixed size of memory in the stack) that is allocated for local variables each time the method is called, and deallocated when th...

Answered by: Ramanuj on: Oct 20th, 2012

Hi,

I have a query. The lifetime of the static variable is the entire program - if it is a local auto variable (i.e., not dynamically allocated), will it contribute to the peak memory ?

Regards,
Ramanu

What is meant by class space and object space (with regards to memory) in c++?

Asked By: mohana.sundaram91 | Asked On: Oct 18th, 2012

I am a slow learner so I would like to have answers that are simple in words but brief.

Why the size of empty class is one byte?

Asked By: varun goswami | Asked On: Feb 16th, 2007

Answered by: bhiku on: Oct 10th, 2012

Yes, but we can put in other way also as we all know we have some default memfunctions created by compiler they are default constructor, default destructor, default copyactor, default assignment opera...

Answered by: a_l_soni on: Nov 27th, 2009

As per MSDN: "The sizeof operator never yields 0, even for an empty class." When you calculate the size of a empty class that time you can c it takes 1 byte.which is the size of a char which...

What is encapsulation?

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

Packaging an object’s variables within its methods is called encapsulation.

Answered by: sakshi on: Oct 4th, 2012

The wrapping up of data and code into a single entity is known as encapsulation.It is a way to implement data abstraction

Answered by: anjala on: Sep 22nd, 2012

encapsulation is the process of wrapping of data member and functions in to a single unit

Write a simple program for finding factorial in C++ ?

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

Answered by: sakshi on: Oct 4th, 2012

Code
  1. class factorial
  2. {
  3. public static void main(String args[])
  4. int f=1,i,n;
  5. n=Convert.ToInt32(Console.ReadLine());
  6. for(i=1;i<=n;i++)
  7. {
  8. f=f*i;
  9. }
  10. Console.WriteLine("factorial of the no :"+f);
  11.  
  12. Console.ReadKey();
  13. }

Answered by: Anugya Singh on: Sep 4th, 2012

Code
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a,i,f=1;
  7. cout<<"Enter the Number whose factorial value is to be find
  8. ";
  9. cin>>a;
  10. for(i=a;i>0;i--)
  11. {
  12. f=f*i;
  13. }
  14. cout<<"Fctorial is "<<f;
  15. getch();
  16. }

What are limitations of union?

Asked By: Tapas Mallick | Asked On: Aug 19th, 2012

Empty declaration of a class holds memory 1 byte

Asked By: Rajesh kumar777 | Asked On: May 31st, 2012

Why empty declaration of a class holds memory 1 byte. Explain briefly?

Answered by: Nil on: Aug 5th, 2012

Different objects must have different addresses.

Code
  1. Something *somethigns = new Something[2];
  2. if(somethings[0]==somethings[1])
  3.     exit(-1); // This line must never run.
  4. delete[] somethings;

Function pointer

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

How to assign function pointer to static function?

Answered by: ak.nextptr on: Jul 31st, 2012

if int fn(char ch,int a) is static function then
function pointer type to above static function will be
int (*)(char , int )

Answered by: cooder on: Apr 26th, 2012

Using the class name. In case of non static function we need to use the this pointer.

First | Prev | | Next | Last Page

 

 

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.