Find jobs | Company-wise jobs
Jobseekers | Employer login
About us Sitemap of www.CareerRide.com Sitemap FAQ related with www.CareerRide.com FAQ Click here to Contact us Contact
       
Submit Resume Free ! | Access Resume Free !
Home Interview Q&A Tutorials Oracle Sql server .NET Java Soft skills CV GD Work from home Online practice test FAQs in PDF Books Jobs FAQs
Interview questions                  
C++ interview
C interview
C test!
C++ test!
Data structure test!
C++ access control
C++ COM
C++ constructors destructors
C++ containers
C++ DCOM
C++ derived class
C++ error handling
C++ exception handling
C++ friend members
C++ inheritance
C++ inline function
C++ memory leaks
C++ namespaces
C++ new and delete
C++ operator overloading
C++ pointers
C++ references
C++ static data
C++ syntax
C++ template
C++ type checking
C++ virtual functions
C++ pure virtual functions
C++ as an object-oriented
More concept of C++
C++ data types
C++ control constructs
C++ collections
C++ functions
C++ arrays
C++ C-string
C++ classes and structure
C++ Friend functions & classes
C++ polymorphism
C++ multiple inheritance
C++ function template
C++ class templates
C++ standard stream class
ATL server
Data structure in C++
 

C++ interview questions 

Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6    Next>>
When is dynamic checking necessary?

Latest answer: Dynamic checking is necessary in the following scenarios: Whenever the definition of a variable is not necessary before its usage..............
Read answer

Define structured programming.

Latest answer: Structured programming techniques use functions or subroutines to organize the programming code. The programming purpose is broken into smaller pieces.............
Read answer

Explain object oriented programming.

Latest answer: Object oriented programming uses objects to design applications. This technique is designed to isolate data. The data and the functions that operate on the data are combined into single unit..............
Read answer

What are the ways to comment statement in C++?

Latest answer: C++ supports two types of comments..............
Read answer

What is structure in C++?

Latest answer: The C++ programming technique allows defining user defined datatypes through structure. The syntax to declare structure is as follows:.............
Read answer

What is reference variable in C++?

Latest answer: A reference variable is just like pointer with few differences. It is declared using & operator. A reference variable must always be initialized. The reference variable.............
Read answer

What is class using C++?

Latest answer: A class holds the data and functions that operate on the data. It serves as the template of an object..............
Read answer

What is local class in C++?

Latest answer: Local class is define within the scope of a function and nested within a function..............
Read answer

What is the default access level?

Latest answer: The access privileges in C++ are private, public and protected. The default access level assigned to members of a class is private..............
Read answer

What is friend class in C++?

Latest answer: When a class declares another class as its friend, it is giving complete access to all its data and methods including private and protected data and methods to the friend class member methods..............
Read answer

Explain default constructor. What is a default constructor?

Latest answer: Default constructor is the constructor with no arguments or all the arguments has default values..............
Read answer

Define abstraction. What is abstraction? What is an abstraction and why is it important?

Latest answer: The process of hiding unnecessary data and exposing essential features is called abstraction. Abstraction is separating the logical properties from implementation details..............
Read answer

What is overriding?

Latest answer: Defining a function in the derived class with same name as in the parent class is called overriding. In C++, the base class member can be overridden by the derived.............
Read answer

What is copy constructor?

Latest answer: A copy constructor is a special type of constructor that is used to create an object as a copy of an existing object..............
Read answer

Define private, protected and public access control.

Latest answer: Private is the default access specifier for every declared data item in a class. Private data belongs to the same class in which it is created and can only be used.............
Read answer

What is Turbo C++?

Latest answer: Turbo C++ provides an environment called IDE (Integrated Development.............
Read answer

How to control the number of chars read in a string by using scanf()?

Latest answer: Doing this limits the length of the characters that will be read by scanf() to 20 characters maximum although the buffer can hold 25 characters. .............
Read answer

How to detect an end of a file?

Latest answer: You can either use the ifstream object ‘fin’ which returns 0 on an end of file or you can use eof().............
Read answer

What are recursive functions? What are the advantages and disadvantages of Recursive algorithms?

Latest answer: A recursive function is a function which calls itself.  The advantages of recursive functions are: -Avoidance of unnecessary calling of functions. A substitute for iteration where the iterative solution is very complex..............
Read answer

What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator.

Latest answer: An internal iterator is implemented by the member functions of the class which has the iteration logic..............
Read answer

Explain passing objects by reference, passing objects by value and passing objects by pointer.

Latest answer: Pass by value: The callee function receives a set of values that are to be received by the parameters. All these copies of values have local scope, i.e., they can be accessed only by the callee function..............
Read answer

Explain the concepts of throwing and catching exceptions with an example using C++.

Latest answer: C++ provides a mechanism to handle exceptions which occurs at runtime. C++ uses the keywords – throw, catch and try to handle exception mechanism..............
Read answer

What are the advantages of “throw.....catch” in C++?

Latest answer: The following are the advantages of throw and catch in c++. Code isolation: All code that is to be handled when an exception raises is placed in the catch block, which is not part of the original code..............
Read answer

What are friend classes? What are advantages of using friend classes?

Latest answer: The friend function is a ‘non member function’ of a class. It can access non public members of the class. A friend function is external to the class definition..............
Read answer

What are zombie objects in C++? Explain its purpose.

Latest answer: An object creation of a class is failed before executing its constructor. As a constructor would not return a value, there is no confirmation that whether the constructor is executed completely or not..............
Read answer

Explain the difference between Stack and Queue

Latest answer: Stack is a Last in First out (LIFO) data structure whereas Queue is a First in First out (FIFO) data structure..............
Read answer

What is Stack? Explain its uses.

Latest answer: Stack is a Last in First out (LIFO) data structure. It is a linear structure and one can insert and delete from one end only which is called the top. It is very effective in.............
Read answer

What is a Wrapper class?

Latest answer: Wrapper classes are classes that allow primitive types to be accessed as objects..............
Read answer

What do you mean by stack unwinding?

Latest answer: When an exception is thrown, C++ calls destructors to destroy all the objects formed since the beginning of the try block. The objects are destroyed in the.............
Read answer

What is the use of ‘using’ declaration?

Latest answer: In using-declaration, we have using keyword followed by a fully qualified name of a namespace member..............
Read answer

What is the difference between Mutex and Binary semaphore?

Latest answer: Semaphore synchronizes processes where as mutex synchronizes threads running in the same process..............
Read answer

What is the scope resolution operator?

Latest answer: Scope resolution operator allows a program to reference an identifier in the global scope that is hidden by another identifier with the same name in the local scope..............
Read answer

What are the advantages of inheritance?

Latest answer: Code reusability
Saves time in program development..............
Read answer

What is a conversion constructor?

Latest answer: It is a constructor that accepts one argument of a different type..............
Read answer

Explain the advantages of inline functions.

Latest answer: It relieves the burden involved in calling a function. It is used for functions that need fast execution..............
Read answer

Explain the different access specifiers for the class member in C++.

Latest answer: private: It is default one and can be access from class member of the same class.
protected: The protected members can be access from member functions of the.............
Read answer

What is the importance of mutable keyword?

Latest answer: The mutable keyword allows the data member of a class to change within a const member function..............
Read answer

Pointer vs. reference.

Latest answer: A reference must be initialized at the time of declaration whereas not needed in case of pointer. A pointer can point to a null object..............
Read answer

Explain how to call C functions from C++.

Latest answer: The extern keyword is used to call C functions from C++.............
Read answer

How do we declare a class as a friend of another class?
Class vs. Structure

Latest answer: Class: Class has private as default access specifier. Default inheritance type is private..............
Read answer

Explain how to call a base member function from derived class member function.
Is it possible to overload a constructor?

Latest answer: Yes it is possible. A constructor can be overloaded to pass different arguments to the object..............
Read answer

Overriding vs. overloading

Latest answer: Overloading means having methods with same name but different signature
Overriding means rewriting the virtual method of the base class.............
Read answer

What do you mean by binding? Static vs. dynamic binding

Latest answer: Binding means connecting the function call to a function implementation..............
Read answer

What is abstract class?

Latest answer: A class whose object can't be created is abstract class. You can create a class as abstract by declaring one or more virtual functions to pure..............
Read answer

Vector vs. Map

Latest answer: In a vector, all the elements are in a sequence whereas Map stores element in the form of a key-value association pair..............
Read answer

List down elements of an object oriented language.

Latest answer: A class is a user defined data type. It serves as a template of the objects.....
Read answer

Explain constructors and destructors.

Latest answer: Constructors are the member functions of the class that executes automatically whenever an object.......
Read answer

Define access privileges in C++.

Latest answer: You have access privileges in C++ such as public, protected and private that helps.........
Read answer

Explain the difference between structures and classes

Latest answer: Syntactically and functionally, both structures and classes are...........
Read answer

Explain container class and its types in C++.

Latest answer: A container stores many entities and provide sequential or direct access to them. List, vector and strings are............
Read answer

Define storage classes in C++

Latest answer: Storage class defined for a variable determines the accessibility and longevity of the variable. The accessibility.......
Read answer

Define an Iterator class

Latest answer: A container class hold group of objects and iterator class is used to traverse through the objects maintained..........
Read answer

What are pure virtual functions?

Latest answer: The base class with pure virtual function can't be instantiated since there is no definition...........
Read answer

ATL Server interview questions

Latest answer: Explain the concepts and capabilities of ATL Server. Explain the ATL Server architecture.
Why ATL Server? What is SRF Files? Explain with an example................
Read answer

C++ COM and Active X: Interview Questions

Latest answer: What is the STL, standard template library? What is the object serialization? What are ActiveX and OLE. What are GUID? Why does COM need GUIDs? What is a type library? What is the IUnknown interface? Explain Binary object model. How does COM provide language transparency?..........
Read answer

What is object oriented programming (OOP)?
What are the various elements of OOP?
Explain an object, class and Method.
Define Encapsulation and Information Hiding in OOP.
Explain Inheritance and Polymorphism in OOP.
What are the advantages of OOP? 

C++ interview questions - posted on September 30, 2009 at 15:50 AM by Vidya Sagar

Explain how to call C code from C++ code. Explain with an example.

To call a C program in C++ , the basic requirement is both the compilers and runtime libraries must be compatible. They must define the primitive data types such as int, float, char etc.

Accessing C Code From Within C++ Source:

A linkage specification is provided by C++, which is used to declare a function that follows the program linkage conventions for a supported language. C++ compilers support C linkage for compatible C compilers.

To access a function with C linkage, the function need to be declared to have C linkge.

The following code snippet depicts the linkage declaration:

extern "C" {
          void f(); // C linkage
          extern "C++" {
                  void g(); // C++ linkage
                  extern "C" void h(); // C linkage
                  void g2(); // C++ linkage
          }
          extern "C++" void k();// C++ linkage
                     void m(); // C linkage
}

The following code snippet depicts the inclusion of a c header file.

extern "C"
{
       #include "header.h"
}

How can an object of a C++ class be passed to or from a C function?

Define a header file for both C and C++ compilers. The following code snippet does this.

Fred.h:

/* This header can be read by both C and C++ compilers */

#ifndef FRED_H
#define FRED_H

#ifdef __cplusplus
    class Fred {
    public:
         Fred();
         void wilma(int);
    private:
         int a_;
     };
#else
     typedef
          struct Fred
          Fred;
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if defined(__STDC__) || defined(__cplusplus)
      extern void c_function(Fred*); /* ANSI C prototypes */
      extern Fred* cplusplus_callback_function(Fred*);
#else
      extern void c_function(); /* K&R style */
      extern Fred* cplusplus_callback_function();
#endif

#ifdef __cplusplus
}
#endif

#endif /*FRED_H*/

Write C++ code as follows:

Fred.cpp:
// This is C++ code

#include "Fred.h"

Fred::Fred() : a_(0) { }
void Fred::wilma(int a) { }
Fred* cplusplus_callback_function(Fred* fred)
{
     fred->wilma(123);
     return fred;
}

main.cpp:
// This is C++ code

#include "Fred.h"

int main()
{
     Fred fred;
     c_function(&fred);
     ...
}

Write the following C program as follows:

c-function.c:
/* This is C code */

#include "Fred.h"
void c_function(Fred* fred)
{
      cplusplus_callback_function(fred);
}

Why does COM require GUIDs?

Globally Unique Identifier, a unique 128-bit number used in a windows registry to identify COM DLL. Lot of COM object information is known by identifying the registry and the correct GUID. Windows also identifies the user accounts by a user name and assigns it a GUID. GUIDS are also used by database administrators as primary key values in the databases.

What happens when an object is destroyed that doesn't have an explicit destructor?

Destructor synthesizing is done by a compiler of an object’s class.
For instance, if an object of a class Sample is destroyed without invoking the destructor explicitly, the compiler synthesizes the destructor which destroys the object of the class Sample. This process is done by invoking
Sample::~Sample().

Explain the problem with dynamic type checking.

Authoring code without errors is very difficult using dynamic type checking.
It is hard to read or modify or maintain the code for dynamic type checking.

What is wrong with an object being assigned to itself?

A segfault occurs at runtime.

Explain how static member functions are called.

Static member functions are called by referencing its containing class without using an object. The following code snippet illustrates the use of static member functions.

Test::set_number(22);
Test::print_number();

where set_number() and print_number() are static functions and they are defined as follows in the class Test:

static void set_number(int arg) {
                   si = arg; // si is an int var
         }
         static void print_number() {
             cout << "Value of si = " << si << endl;
         }

What happens when a pointer is deleted twice?

It is not certain and depends. If the value of the pointer is set to 0 soon after first delete, then not operation will perform. If not, there are chances for program crash.

Test your C++ knowledge with our multiple choice questions!

Send request to get more ASP.NET, C++ questions, sample CV and personal interview tips in PDF format

Next>>
 
Want to be hunted by potential employers? Just submit your key skills!

Popular FAQs

.NET .Net Architecture ADO.NET Java Oracle C#.NET
VB.NET DOT.NET AJAX ASP.NET NET Framework OOPS in .NET
C++ Sql Server Data warehousing EJB MySQL Linux
PHP UML Networking Testing XML  
 
Copyright © 2008 - 2010 CareerRide.com. All rights reserved.