Objective type C++ Interview Questions for Freshers

1.What does extern mean in a function declaration?
It tells the compiler that a variable or a function exists,even if the compiler hasn’t yet seen it in the file currently being compiled. This variable or function may be defined in another file or further down in the current file.
2.How do I initialize a pointer to a function?
This is the way to initialize a pointer to a function
void fun(int a)
{
}
void main()
{
void (*fp)(int);
fp=fun;
fp(1);
}
3.How do you link a C++ program to C functions?
By using the extern “C” linkage specification around the C function declarations.
4.Explain the scope resolution operator.
It permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.
5.What are the differences between a C++ struct and C++ class?
The default member and base-class access specifier are different.
6.How many ways are there to initialize an int with a constant?
Two. There are two formats for initializers in C++ as shown in the example that follows. The first format uses the traditional C notation. The second format uses constructor notation.
int foo = 123;
int bar (123);
7.How does throwing and catching exceptions differ from using setjmp and longjmp?
The throw operation calls the destructors for automatic objects instantiated since entry to the try block.
8.What is a default constructor?
Default constructor WITH arguments
class B { public: B (int m = 0) : n (m) {} int n; }; int main(int argc,char *argv[]) { B b; return 0; }
9.What is a conversion constructor?
A constructor that accepts one argument of a different type.
10.What is the difference between a copy constructor and an overloaded assignment operator?
A copy constructor constructs a new object by using the content of the argument object. An overloaded assignment operator assigns the contents of an existing object to another existing object of the same class.
11.When should you use multiple inheritance?
There are three acceptable answers: “Never,” “Rarely,” and “When the problem domain cannot be accurately modeled any other way.”
12.Explain the ISA and HASA class relationships. How would you implement each in a class design
A specialized class “is” a specialization of another class and,therefore,has the ISA relationship with the other class. An Employee ISA Person. This relationship is best implemented with inheritance. Employee is derived from Person. A class may have an instance of another class.
For example,an employee “has” a salary,therefore the Employee class has the HASA relationship with the Salary class. This relationship is best implemented by embedding an object of the Salary class in the Employee class.
13.When is a template a better solution than a base class?
When you are designing a generic class to contain or otherwise manage objects of other types,when the format and behaviour of those other types are unimportant to their containment or management,and particularly when those other types are unknown (thus,the generosity) to the designer of the container or manager class.
14.What is a mutable member?
One that can be modified by the class even when the object of the class or the member function doing the modification is const.
15.What is an explicit constructor?
A conversion constructor declared with the explicit keyword. The compiler does not use an explicit constructor to implement an implied conversion of types. It’s purpose is reserved explicitly for construction.
16.What is the Standard Template Library (STL)?
A library of container templates approved by the ANSI committee for inclusion in the standard C++ specification. A programmer who then launches into a discussion of the generic programming model,iterators,allocators,algorithms,and such,has a higher than average understanding of the new technology that STL brings to C++ programming.
17.Describe run-time type identification.
The ability to determine at run time the type of an object by using the typeid operator or the dynamic cast operator.
18.What problem does the namespace feature solve?
Multiple providers of libraries might use common global identifiers causing a name collision when an application tries to link with two or more such libraries. The namespace feature surrounds a library’s external declarations with a unique namespace that eliminates the potential for those collisions. This solution assumes that two library vendors don’t use the same namespace identifier,of course.
19.Are there any new intrinsic (built-in) data types?
Yes. The ANSI committee added the bool intrinsic type and its true and false value keywords.
20.Will the following program execute? void main()
{
void *vptr = (void *) malloc(sizeof(void));
vptr++;
}
It will throw an error,as arithmetic operations cannot be performed on void pointers.
21.For the following C program
#define AREA(x)(
3.14*x*x)
main()
{
float r1=
6.25,r2=
2.5,a;
a=AREA(r1);
printf(“\n Area of the circle is %f”,a);
a=AREA(r2);
printf(“\n Area of the circle is %f”,a);
}
What is the output?
Ans. Area of the circle is 12
2.656250
Area of the circle is 19.625000
22.void main()
{
int d=5;
printf(“%f”,d);
}
Ans: Undefined
23.void main()
{
int i;
for(i=1;i<4 1:="" 1="" 24.void="" 25.void="" 2:printf="" 3:printf="" 4:printf="" 6="" ans:="" break="" case="" char="" d="" i="1;" k="-1" main="" printf="" s="" sizeof="" switch="" unsigned=""> k=255; */
signed j=-1; /* char k= -1 => k=65535 */
/* unsigned or signed int k= -1 =>k=65535 */
if(i printf(“less”);
else
if(i>j)
printf(“greater”);
else
if(i==j)
printf(“equal”);
}
Ans: less
26.void main()
{
float j;
j=1000*1000;
printf(“%f”,j);
}
1. 1000000
2. Overflow
3. Error
4. None
Ans: 4
27.How do you declare an array of N pointers to functions returning pointers to functions returning pointers to characters?
Ans:
The first part of this question can be answered in at least three ways:
1. char *(*(*a[N])())();
2. Build the declaration up incrementally,using typedefs:
typedef char *pc; /* pointer to char */
typedef pc fpc(); /* function returning pointer to char */
typedef fpc *pfpc; /* pointer to above */
typedef pfpc fpfpc(); /* function returning… */
typedef fpfpc *pfpfpc; /* pointer to… */
pfpfpc a[N]; /* array of… */
3. Use the cdecl program,which turns English into C and vice versa: cdecl> declare a as array of pointer to function returning pointer to function returning pointer to char
char *(*(*a[])())()
28.What is a modifier?
A modifier,also called a modifying function is a member function that changes the value of at least one data member. In other words,an operation that modifies the state of an object. Modifiers are also known as ‘mutators’.
29.What is an accessor?
An accessor is a class operation that does not modify the state of an object. The accessor functions need to be declared as const operations
30.Differentiate between a template class and class template.
Template class:
A generic definition or a parameterized class not instantiated until the client provides the needed information. It’s jargon for plain templates.
Class template:
A class template specifies how individual classes can be constructed much like the way class specifies how individual objects can be constructed. It’s jargon for plain classes

Related

Interview Questions 2536869515182191588

Post a Comment

emo-but-icon

item