C And C++ interview question with Answer
1.
What is coercion?
Ans: The Type Casting
is also known as coercion IN ‘C’.
2.
What is the size of a character
literal in C?
Ans: 2 byte/4 byte depending upon compiler
3.
What is the use %g?
Ans: it is a conversion char used to represent a
floating point number either in decimal format or exponential format according
to size.
4.
What is ellipsis?
Ans: (…) is known as ellipsis which represent a
variable no’s or types of argument.
5.
How many arguments main() function can
take?
Ans: 3
6.
main() function is predefined or user
defined?
Ans: System
specified user defined
7.
What header files contain?
Ans: Function
declarations and MACRO
8.
What is size of union variable?
Ans: Size of the max size member
9.
What is a self referential structure?
Ans: the structure
which contains a pointer to itself
10.
Can a union be self-referenced?
Ans: No
11.
What does segmentation violation
means?
Ans: This error
occurs when program access a memory that it should not have or to which access
is not granted.
12.
What is the little endian and big
endian?
Ans: Little endian
means the lower order byte of a number is stored in memory at the lowest
address and the high order bytes at the heighest address. Big endian is
reverse.
13.
What is the difference between exit()
and _exit() functions?
Ans: exit() flush
the standard I/O buffer but _exit() does not flush the standard I/O buffer.
14.
What is the difference between
strcpy() and memcpy()?
Ans: strcpy copy chars form one string to another
till ‘\0’ i.e. Null char
Memcpy copy chars from one string to
another till a given length.
15.
What is bit-field?
Ans: The
space-saving structure members are called bit fields, and their width in
bits can be explicitly declared.
16.
What is NULL macro?
And: NULL is a
macro that is used to represent null pointer in source code.
17.
What is the different between far
pointer and huge pointer?
Ans: Far pointer
does not normalize the address but huge pointer normalize the address.
18.
What is effect of using %n in scanf?
Ans: it represent the
the no of chars input from keyboard.
19.
Difference between expression and a
statement.
Statement must have
a semicolon but expression may not have semicolon.
20.
What is loop inversion?
Ans: Loop inversion is a compiler optimization, a loop transformation, which replaces a while
loop by an if block containing a do..while loop.
21.
What is side effect of a variable?
Ans: The changes to
a global variable in one block will be an effect in another block.
22.
What are the limitations of bit
fields?
Ans: We can not
input its values using scanf
We can not have a pointer to bit field
23.
What the use of volatile keyword?
Ans: C's volatile keyword is a qualifier that is
applied to a variable when it is declared. It tells the compiler that the value
of the variable may be changed by an external agent like operation system sub
routines.
24.
int a=5,b=7;
a^=b^=a^=b;
printf(“%d %d”,a,b);
Ans:
7 5
25.
int a=0,b=0,c=0,d;
d=a++ || b++ && ++c;
printf("%d %d %d %d", a, b, c,d);
Ans:
1 1 0 0
26.
#define scanf “%s is string”
main()
{
printf(scanf,scanf);
}
Ans:
% is string is string
27.
int x=0,y=0,z;
z=~x+~y;
printf("%d",z);
Ans:
-2
28.
int main()
{
int x;
x=main();
printf(“%d”,x);
return 0;
}
Ans:
infinite loop
29.
int arr[ ]={0,1,2,3,4};
int
*p,i;
for(p=arr+4, i=0;i<=4;i++)
printf(“%d “, p[-i]);
Ans:
4 3 2 1 0
30.
main()
{
int
i=0;
for(;++
i ;);
printf(“%d”,i
);
}
Ans:
0
31.
What is wchat_t in C++?
Ans: Wide character
type
32.
What is name mangling?
Ans: Conversion of
a function name into a code according to nos and types of argument.
33.
What is VTABLE?
Ans: Virtual Table
which stores the addresses of virtual functions of a class
34.
What is VPTR?
Ans: Virtual
pointer through which virtual functions are accessed
35.
What is RTTI?
Ans: Runtime type
identification
36.
What is reinterpret cast?
Ans: It convert one
type directly into another - such as casting the integer value to an integer
pointer.
37.
What is Composition?
Ans: The
containership or delegation is also known as composition
38.
What is object slicing?
Ans: When a derived
class object is assigned to a base class object it is divided into two parts.
One is base portion that is copied to
the base class object and other is the derived portion that is slices off.
39.
What is upcasting?
Ans: conversion of
a derived class object to a base class object
40.
Can pure virtual function have a body?
Ans: Yes
41.
What is the use of explicit keyword?
Ans; to explicitly
call a constructor.
42.
What is the use of mutable keyword?
Ans: If a data
member is declared with mutable that can be modified by a constant member
function.
43.
What is a pointer to constant?
Ans: It is a pointer to whom it points to can not
be modified
44.
What is the size of an abject of empty
class?
Ans: one byte
45.
Which operator automatically calls the
destructor?
Ans: delete
Comments
Post a Comment