| Back to Questions Page |
| |
| Question |
Is there something that we can do in C and not in C++? |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
| This Interview Question Asked @ Patni |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | Theoratically it is being said that we cannot call main
recursively(main caling main) in c++, but practically it can
be done.
whereas in c, we can call main in main.  |
| Guest |
| |
| |
| Answer | Pointers we can do it in c but not in c++  |
| Tajudeen |
| |
| |
| Answer | we can use printf in c but not in c++  |
| Avni |
| |
| |
|
|
| |
| Answer | there are many concepts that can be used in c++ where c
cannot support those concepts.
The following are some of those type of concepts:-
1.function overloading
2.operator overloading
3.templates
4.polymorphism
5.inheritence
6.data encapsulation
7.function over-riding
8.virtual functions
9.constructors & destructors
10. exceptional handling.  |
| Vaishnavi |
| |
| |
| Answer | nothing  |
| Kiran.raikar |
| |
| |
| Answer | every C program is execute in C++.
From the above reason we can understand that every thing in
C we have in c++ also.
so Answer is NOTHING  |
| Prathap |
| |
| |
| Question |
What is a "RTTI"? |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
| This Interview Question Asked @ HCL , Hcl |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | RTTI stands for run time type identification.  |
| Roshanpr |
| |
| |
| Answer | RUN TIME TYPE INFORMATION. Afacility that allows an object
to b queried at runtime to determine its type.  |
| Sarmistha |
| |
| |
| Answer | RTTI stands for Run Time Type Information.It is used to
provide information about the dynamic type of an object.  |
| Manju |
| |
| |
| Answer | Declares a TestNamer for the specified type, using RTTI if
enabled, otherwise using macro string expansion.
RTTI is used if CPPUNIT_USE_TYPEINFO_NAME is defined and
not null.
Run-time Type Information  |
| Vijayanand |
| |
| |
| Answer | already they had given abbr actually to find the runtime spec
we are using typeid() and typeinfo().  |
| Saravanan |
| |
| |
| Question |
What is "mutable" keyword? |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | mutable key word is used when u want to make any member
variable of a const object modifyable.
Basically when u make a object constant u cannot modify its
data members. But during the declaration of the class if a
data member is declared as mutable it can changed.
Class my
{
mutable int age;
public:
my(){age=0;}
void plusplus(int b)const
{
age+=b;
}
};
int main()
{
const my obj;
obj.plusplus(40);
}  |
| Roshanpr |
| |
| |
| Answer | Mutable keyword is used to modify a data member of an object
which has declared as constant. for example:
class XYZ
{
public:
int i;
mutable int cc;
public:
XYZ();
};
int main()
{
const XYZ obj;
obj.cc = 100; // modify obj object's member "cc" which has
been declared as mutable.
}  |
| Shakti Singh Khinchi |
| |
| |
| Question |
Explain "passing by value", "passing by pointer" and
"passing by reference" ? |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | During pass by value a duplicate copy of the parameters
passed are created. Any changes made to copy will not
reflect the actual parameters.
In pass by pointer(it called as pass by address) duplicate
copy is not created. and any chagnes made to copy will
reflect in actual parameters also.  |
| Roshanpr |
| |
| |
| Answer | Pass by value - a copy is made
Pass by pointer ( explicit pointer)
example:
void func(int * ptr_sent)
main()
{
int i;
int *p;
p = &i;
func(p);
}
void func(int * ptr_sent)
{
*ptr_sent = *ptr_sent + 2
// adds 2 to the value in location pointed by ptr_sent
}
Pass by reference (implicit pointer)
example:
void func(int &ref_sent)
main()
{
int i;
func(&i);
}
void func(int &ref_sent)
{
ref_sent = ref_sent + 2
// adds 2 to the ref_sent
// Please note that you do not need * when using reference
// Any code manipulating reference reflects changes on i
}  |
| Ven |
| |
| |
| Answer | In Pass by value,copy of the value is passed, but in pass by
reference the address of the variables are passed as a
reference.pointer are variables storing the address of
another variable so it can be used as a pass by referece,
den it s teamed "passing by pointer".  |
| Sanish Joseph |
| |
| |
| Answer | Pass by value - a copy is made
Pass by pointer ( explicit pointer)
example:
void func(int * ptr_sent)
main()
{
int i;
int *p;
p = &i;
func(p);
}
void func(int * ptr_sent)
{
*ptr_sent = *ptr_sent + 2
// adds 2 to the value in location pointed by ptr_sent
}
answers given by yen .. there is one error ... in pass by
reference .. when calling function pass the variable not
the address....fun(i) should be called instead of fun(&i)
Pass by reference (implicit pointer)
example:
void func(int &ref_sent)
main()
{
int i;
func(i); // call by reference
}
void func(int &ref_sent)
{
ref_sent = ref_sent + 2
// adds 2 to the ref_sent
// Please note that you do not need * when using reference
// Any code manipulating reference reflects changes on i
}  |
| Ranjeet Garodia |
| |
| |
| Answer | i am not agree with Ranjeet, you mention this
main()
{
int i;
func(i); // call by reference
}
but fun(i) is a call by value not call by reference
your code will give compile error.
Ven eample is right.  |
| Sampurna Pandey |
| |
| |
| Question |
What is "strstream" ? |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
| This Interview Question Asked @ Huawei |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer |
strstream is the class that specializes iostream to use a
strstreambuf for input and output with arrays of characters
in memory.
The class strstream provides functionality to read and
write to an array in memory. It uses a private strstreambuf
object to control the associated array. It inherits from
basic iostream and therefore can use all the formatted and
unformatted output and input functions.  |
| Sv |
| |
| |
| Question |
What are inline functions? |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
| This Interview Question Asked @ Verizon |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | Functions that are expanded inline ( that we during there
call) is called inline functions.
Usually when there there is a function call the control is
taken to the function definition where the code is executed
and then the control returns back to main. But in case of
inline function there is no jump in the flow, rather the
function it self is expanded at the place of call.
You can make function inline in two ways.
1) Prefixing keyword "inline" durin the function
declaration.
2) By defining the function inside the class declaration
Ex: shows both the implementation
Class myClass
{
int age;
public:
inline void getAge();
void showAge()
{
cout<<"Age:"<<age;
}
};
void myClass getAge()
{
cout<<"Age:"<<age;
}  |
| Roshanpr |
| |
| |
| Answer | Inline function :-
In genereal function call branching method is there . In
inline function substitution takes place . Inline
functions are expanded during compilation . Exectution
becomes fast and branching is eliminated. Inline word is a
request but not command. If inline is not possible compiler
takes it like a genral function call.
rules:
1 function should be small
2. Controll statements are not valid like for ,while
if u need more mail to me  |
| Laxman |
| |
| |
| Question |
How to write a program such that it will delete itself after
exectution? |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | I am not sure but I guess create a destructor  |
| Ven |
| |
| |
| Question |
What is the Difference between "vector" and "array"? |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
| This Interview Question Asked @ TCS , Covnsys, Gambit Technology |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | a vector is also like an array i.e sequentially accessed but
we can increase/decrease size of a vector in a simple way
than it is done for arrays.  |
| Guest |
| |
| |
| Answer | vector is also an array but the size of a vector can change
dynamically where in array its fixed.
we can create some reserve space in vector where in array we
cannot.  |
| Vishwa |
| |
| |
| Answer | as we know in C++ the size of array is fixed in compile
time .so the size of array cannot be adjusted at run time
to accommodate changeling program .
but vector can solve this problem allocating memory as
needed. although vector is dynamic  |
| Saroj Das , |
| |
| |
| Answer | A growable array is calld vector while array is of fixed size,  |
| Sanish Joseph |
| |
| |
| Answer | First, a vector is a template class but not the array is.
So obviously there are members to access the elements of
the vector like, range checking, iterators,
insertion/deletion, predicates, etc.
Since it is a template class, the same implementation can
be used for any type including pointers, objects/user
defined types.
Second, as said by others, vector automatically grow as we
invoke push_back(), we can reserve additional space for
elements, etc.  |
| Mms Zubeir |
| |
| |
| Answer | We know that arrays and Vectors in Java are different kinds
of data structures for storing information in a
random-access fashion. In Java, an object-oriented language,
the two structures are implimented as classes. This
presentation will demonstrate some of the principle
differences between Java arrays and Java Vectors. It will
also provide some examples of the cool methods that come
with them.
Arrays
Arrays in Java are static lists declared to store a certain
number of a certain kind of variables. It stores these
values at specific, numbered locations in a list that starts
at zero and goes to N-1:
myArray Index Data
0 14
1 79
2 32
3 92
4 102
This array can be instantiated in Java with either the
shorthand syntax:
int[] myArray = new int[5];
int myArray[] = new int[5];
or an explicit method call to a Java "Array" class object:
int[] myArray = Array.newInstance[int, 5];
When an array is instantiated, the array's constructor
method allocates 5 integer-sized memory slots. The
allocation is static- the array size cannot change after it
is created. In this sense, it is analagous to a C or C++
style array. But the resemblence doesn't end here. Java
Arrays, like C arrays, have undefined contents until they
are initialized. One can set the contents of an array at the
time of instantiation with the simple syntax:
int[] myArray = {14,34,21,42,22};
We have already seen that, in addition to the built-in
C-style array operations syntax there Java provides
additional classes for manipulating arrays. This represents
a desire on the Java authors' part to both a) retain a
grounding in C to attract those programmers already familiar
with the popular language, and b) provide true
object-oriented support for array operations. This is true
for array referencing, as well. Various array-handling
objects exist in the class library java.lang. This provides
interface functions for various array operations For
example, one could refer to the individual array as in C:
fourth_item = myArray[3];
or, one could use the explicit method call:
fourth_item = myArray[3];
Java arrays can also be passed as parameters to functions.
Java permits either a copy of the original array or a
pointer to be sent.
2D-arrays are also supported. This is a statically-allocated
array of array pointers:
int[][] 2D_array = new int[x_length][y_length];
Finally, note that vectors of objects can exist. This does
not mean, however, that the new objects are instantiated
when the array is declared. Arrays take up a fixed size in
memory, and the size of an object isn't defined when it is
instantiated. Therefore, the objects must be instantiated in
a seperate command. Therefore, to create an array of 5
objects, the following code could be used:
object_list = new Object[5];
object_list[0] = new Object();
object_list[1] = new Object();
.
.
.
Vectors
The key difference between Arrays and Vectors in Java is
that Vectors are dynamically-allocated. They aren't declared
to contain a type of variable; instead, each Vector contains
a dynamic list of references to other objects. The Vector
class is found in the java.util package, and extends
java.util.Abstractlist.
The big advantage of using Vectors is that the size of the
vector can change as needed. Vectors handle these changes
through the "capacity" and "capacityIncrement" fields. When
a Vector is instantiated, it declares an object array of
size initialCapacity. Whenever this array fills, the vector
increases the total buffer size by the value
capacityIncrement. Thus, a Vector represents a compromise.
It doesn't allocate each object dynamically, which would
make access of middle list-items exceedingly slow; but it
does allow for growth in the size of the list. The default
constructor, Vector(), creates an empty Vector of initial
capacity zero that doubles in size whenever it fills.
Vectors can be filled using its method addElement(Object
obj). This method appends the given object to the end of the
Vector. Because the Vector stores pointers to the objects,
and not the objects themselves, these Vector items could be
any kind of object. Moreover, several different kinds of
objects could exist in the same Vector. Vector methods allow
all sorts of nifty ways to manipulate data. For example, one
can reference a list item not just by its index, but also by
name. Elements can be removed from or added to the middle of
the list:
myVector.insertElementAt(my_object, 5);
success_flag = myVector.remove(my_object);
So you're thinking, "GREAT! But if vectors are so wonderful,
why even bother with arrays?"
Comparative Advantages of Arrays and Vectors
Because Vectors are dynamically-allocated, they offer a
relatively memory-efficient way of handling lists whose size
could change drastically. The line buffer of a text editor,
for example, could be anywhere from zero to thousands of
entries in size. A Vector might be a good choice for such an
arrangement. Moreover, Vectors have some useful member
functions that make coding simpler (see the insertElementAt
and remove methods above). But because the Vector class is
based on an array of object references, these methods are
generally no more efficient than array-based algorithms. The
insert method must perform multiple "swap" operations just
as an array 'insert' algorithm would. Thus, Vectors are
easier to use than arrays for most applications, but they do
not offer all the performance advantages of fully-dynamic
storage.  |
| Raju |
| |
| |
| Question |
What are the types of STL containers? |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | containers are objects that hold other object . there are
different type vector, dequeue,list, map etc...  |
| Saroj Das , |
| |
| |
| Question |
What is Namespace? |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
| This Interview Question Asked @ Samsung |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | a namespace is a simply declarative region the main purpose
is is to localize the names of identifiers to avoid name
name collisions .  |
| Saroj Das ,balsore |
| |
| |
| Question |
What are the different types of Storage classes? |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | storage class is an instruction that give compiler 4
instructions . there are 4 type storage class 1) automatic,
register , static ,external  |
| Saroj Das ,balsore |
| |
| |
| Answer | There are four types of storage classes.
1.Automatic: The scope is within the class that is like
local to its class
2.Extern: The scope of this is used within the class as
well as outside the class.so it is global
3.Regiter: These are mainly used for faster access of data.
4.Static: Once you declare the variable as static it will
remain constant throughout the program  |
| Manjusinga |
| |
| |
| Answer | answers given by Manjusinga about static is wrong:
it will be
4.Static: Once you declare the variable as static it exist
till the life of the program.  |
| Ranjeet Garodia |
| |
| |
| Question |
What are Virtual Functions? How to implement virtual
functions in "C" ? |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | A function declared with the keyword virtual, termed as
virtual function.It is used for runtime polymorphism. When
a function is declared as virtual function, the function of
that object is invoked which is refernced by the base
pointer.
Example-
class BASE
{
public:
virtual void show()
{
cout<<"withen base";
}
};
class DERIVED:public BASE
{
public:
void show()
{
cout<<"withen derived";
}
};
void main()
{
BASE *b,b1;
DERIVED d1;
b=&b1;
b->show(); //call the BASE show()
b=&d1;
b->show(); //call the DERIVED show()
getch();
}  |
| Arati Pradhan |
| |
| |
| Answer | To address the second part of the question - the only way to
implement mechanism like virtual functions in C is by using
function pointers, creating structure emulating Virtual
Pointer Table etc.
Implementation is rather complicated and creates a lot of
overhead for every structure that we want to use with
virtual functions (since ANSI C doesnt support inheritance
and polimorphism, it also calls for emulating this behavior,
so virtual functions for C is actually more of a form of art
than anything usefull).  |
| Jaroosh |
| |
| |
| Question |
What are the different types of polymorphism? |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | compile time--->operator and function overlaoding
run time --->virtual  |
| Dee |
| |
| |
| Answer | There are two types of polymorphism.
1. Adhoc polymorphism (Overloading, templates).
2. Parametric polymorphism(Overriding).
If the behaviors are finite and known before its usage, it
is adhoc polymorphism. These bindings are done at
compilation itself and hence called compile time binding.
If the behaviors are infinite and known only at run time at
the time of use, it is parametric polymorphism. These
binding can be mapped at run time only and hence sometimes
referred as run time binding.
Note:- Virtual mechanism is used to resolve conflicts in
overriding polymorphically. Virtual mechanism itself
doesn't provide any polymorphism rather the overriding
leads to run time polymorphism.  |
| Mms Zubeir |
| |
| |
| Question |
Can we have "Virtual Constructors"? |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
| This Interview Question Asked @ TCS |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | there is nothing like "virtual constructor"  |
| Shivangi |
| |
| |
| Answer | No, we cannot have virtual constructor. Because constructor
is usually use to create instance of a class and we cannot
make it virtual.  |
| Rani |
| |
| |
| Answer | of course no such concept lie within C++ ,but we can achieve
this effect. Abstract Factory method show this type of effect.  |
| Nishikant Sahu |
| |
| |
| Answer | Yes there is no virtual constructors.I can think a a reason
may be because a constructor is never inherited so there is
no polymorphism etc involved .  |
| Vighnesh |
| |
| |
| Answer | No, we cannot have virtual constructor because at this time
(during object creation or intialization) virtual table not
yet created.  |
| Vadivel |
| |
| |
|
| |
|
Back to Questions Page |