|
Latest answer: Dynamic checking is necessary in the following
scenarios: Whenever the definition of a variable is not necessary before its
usage..............
Read
answer
Latest answer: Structured programming
techniques use functions or subroutines to organize the programming code. The
programming purpose is broken into smaller pieces.............
Read answer
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
Latest answer: C++ supports two types of
comments..............
Read answer
Latest answer: The C++ programming technique
allows defining user defined datatypes through structure. The syntax to declare
structure is as follows:.............
Read answer
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
Latest answer: A class holds the data and
functions that operate on the data. It serves as the template of an
object..............
Read answer
Latest answer: Local class is define within
the scope of a function and nested within a function..............
Read answer
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
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
Latest answer: Default constructor is the
constructor with no arguments or all the arguments has default
values..............
Read answer
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
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
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
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
Latest answer: Turbo C++ provides an
environment called IDE (Integrated Development.............
Read answer
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
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
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
Latest answer: An internal iterator is
implemented by the member functions of the class which has the iteration
logic..............
Read
answer
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
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
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
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
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
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
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
Latest answer: Wrapper classes are classes
that allow primitive types to be accessed as objects..............
Read answer
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
Latest answer: In using-declaration, we have
using keyword followed by a fully qualified name of a namespace
member..............
Read answer
Latest answer: Semaphore synchronizes
processes where as mutex synchronizes threads running in the same
process..............
Read answer
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
Latest answer: Code reusability
Saves time in program development..............
Read answer
Latest answer: It is a constructor that
accepts one argument of a different type..............
Read answer
Latest answer: It relieves the burden
involved in calling a function. It is used for functions that need fast
execution..............
Read answer
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
Latest answer: The mutable keyword allows
the data member of a class to change within a const member
function..............
Read answer
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
Latest answer: The extern keyword is used to
call C functions from C++.............
Read
answer
Latest answer: Class: Class has private as default access
specifier. Default inheritance type is private..............
Read answer
Latest answer: Yes it is possible. A
constructor can be overloaded to pass different arguments to the
object..............
Read answer
Latest answer: Overloading means having
methods with same name but different signature
Overriding means rewriting the virtual method of the base class.............
Read answer
Latest answer: Binding means connecting the
function call to a function implementation..............
Read answer
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
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
Latest answer: A class is a user defined
data type. It serves as a template of the objects.....
Read answer
Latest answer: Constructors are the member
functions of the class that executes automatically whenever an object.......
Read answer
Latest answer: You have access privileges in
C++ such as public, protected and private that helps.........
Read answer
Latest answer: Syntactically and
functionally, both structures and classes are...........
Read answer
Latest answer: A container stores many
entities and provide sequential or direct access to them. List, vector and
strings are............
Read answer
Latest answer: Storage class defined for a
variable determines the accessibility and longevity of the variable. The
accessibility.......
Read answer
Latest answer: A container class hold group
of objects and iterator class is used to traverse through the objects
maintained..........
Read answer
Latest answer: The base class with pure
virtual function can't be instantiated since there is no definition...........
Read answer
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
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.
Send
request to get more ASP.NET,
C++ questions, sample CV and personal interview tips in PDF
format
|