ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories >> Software >> Programming-Languages >> C++
 
  STL (45)  OOPS (186)  C++-General (222)
 


 

Back to Questions Page
 
Question
What is the output of:

String a1 = "Hello";
String a2 = "world!";
String* s1 = &a2;
String& s2 = a1;
s1 = &a1;
s2 = a2;
std::cout << *s1 << " " << s2 << std::endl;
Rank Answer Posted By  
 Question Submitted By :: Seeker
This Interview Question Asked @   Lehman-Brothers
I also faced this Question!!   © ALL Interview .com
Answer
Hello World
 
5
Saranya
 
 
Answer
The output is 

world! world!

This is becuase s2 is a reference variable of a1 and we are 
assigning s2 value if a2 which is world!.

This is chnaging the value at a1 as well.
 
5
Ratan
 
 
Answer
address of a1 hello
 
0
Dsp
 
 
 
Answer
world! world!  is the right anwer.
Do not confuse with other asnwers.
Same is verified.
 
0
Pokala
 
 
Question
In C++ cout is:
a) object
b) class
c) something else
Rank Answer Posted By  
 Question Submitted By :: Seeker
This Interview Question Asked @   Lehman-Brothers
I also faced this Question!!   © ALL Interview .com
Answer
Stream Object
 
0
Sanjay Makwana
 
 
Answer
ANSWER IS C. COUT IS AN BUID IN OPERATOR THAT WAS DEFINED 
IN HEADER FILE: <IOSTREAM.H>
SINCE, IN C++ COUT IS AN CONSOLE OUTPUT OPERATOR.
 
0
Sriram
 
 
Answer
cout is an object of class ostream that represents the 
standard output stream. It corresponds to the cstdio stream 
stdout.

By default, most systems have their standard output set to 
the console, where text messages are shown, although this 
can generally be redirected.

Because cout is an object of class ostream, we can write 
characters to it either as formatted data using for example 
the insertion operator (ostream::operator<<) or as 
unformatted data using the write member function
 
3
Chandra
 
 
Answer
Its an Object of class OStream, thats why we add its 
corresponding header file that is <iostream.h>, Open this 
header file you wil get complete infomation.
 
0
Reejusri
 
 
Answer
The answer is someting else.

cout is an ostream opertor.
 
0
Manju
 
 
Answer
C++ treats everything as an object.me,u,we,cout all are 
object in C++.So cout is an object.
 
1
Kiruthika
 
 
Answer
a, it is an object in C++
 
0
Ganesh
 
 
Answer
ans is a) it is an object of ostream_withassign.
 
0
Hemant Majithia
 
 
Answer
object of ostream_withassign. (a) is the right answer.
 
0
Shakti Singh Khinchi
 
 
Answer
cout is an object.....
 
0
Vaibhav Meena
 
 
Question
Write a String class which has:
1) default constructor
2) copy constructor
3) destructor
4) equality operator similar to strcmp
5) constructor which takes a character array parameter
6) stream << operator
Rank Answer Posted By  
 Question Submitted By :: Seeker
This Interview Question Asked @   Lehman-Brothers , Zoomtrang
I also faced this Question!!   © ALL Interview .com
Answer
#include <iostream>
#include <string.h>


using namespace std;

class ownStrcmp
{
public:
	ownStrcmp(){}
	ownStrcmp(ownStrcmp& rhs);
	ownStrcmp(char* instring){ _string = instring;}
	void setString(char* instring){ _string = instring;}
	char* getString(){return _string ;}
	~ownStrcmp(){}
	int operator == ( ownStrcmp &rhs);

private:
	char* _string;
	bool _ret;

};

ownStrcmp::ownStrcmp(ownStrcmp& rhs)
{
	_string = rhs._string;
}
int ownStrcmp::operator == ( ownStrcmp &rhs)
{
	_ret = true;
	if(this == &rhs) 
	{	
		return _ret;
	}
	int i = 0;
	while( _string[i] != NULL){ ++i;}
	int stringLength = i;
	for (int j=0;j<stringLength;j++)
	{
		if(_string[j]!=rhs._string[j]) _ret=false;
	}
	return _ret;
}


int main()
{ 
  ownStrcmp string1("hello world");
  ownStrcmp string2("hello world");
  if (string1 == string2)
  cout<<"result is true"<<endl;
  else
	cout<<"result is false"<<endl;
  return 0; 
}
 
0
Stevewu
 
 
Question
Write a function which takes a character array as input and
reverses it in place.
Rank Answer Posted By  
 Question Submitted By :: Seeker
This Interview Question Asked @   Lehman-Brothers , Vision Infotech
I also faced this Question!!   © ALL Interview .com
Answer
void reverse(char *a)
{
	char tmp; 
	int len = strlen(a) - 1;

	for (int i = 0; i < len/2; i++)
	{
		tmp = a[i];
		a[i] = a[len - i];
		a[len - i] = tmp;
	}
}
 
0
Gumnam
 
 
Answer
#include<iostream>

using namespace std;

void reverse(char *a)
{
	char *tmp = new char[strlen(a)];
	memset(tmp,0,strlen(tmp));
	int a1 = strlen(a);
	a1 =a1-1;
	for (int i = a1;i>=0; i--)
	{
		tmp[a1-i] = a[i];
	}
	cout<<tmp<<"       "<<strlen(tmp)<<endl;
}

void main()
{
	char *name = "Xerox";
	reverse(name);
}
 
0
Arun
 
 
Question
what is new modifier in C#
Rank Answer Posted By  
 Question Submitted By :: Govindhinge
This Interview Question Asked @   HCL
I also faced this Question!!   © ALL Interview .com
Answer
hi
 
0
Kiran
 
 
Answer
C# allow redefinition of inherited methods in the derived 
classes at the cost of hiding the inherited ones using new 
modifier.
 
5
Pratyaya Kumar Ghosh
[STPL]
 
 
Answer
Mr.kiran this site is not for sending "hi" type nessages.
please dont misuse the site.
thanq
 
0
Anna
[STPL]
 
 
Answer
HEI ANNA
This site is not for commenting 'bout others answers.u were 
the one who misused the site by commenting!!!!

thnx
 
0
Rahul P.v
[STPL]
 
 
Answer
hi Rahul,
 what u did, are u not misusued?
 
0
Viswanath
[STPL]
 
 
Answer
When used as a modifier, the new keyword explicitly hides a 
member inherited from a base class. Hiding an inherited 
member means that the derived version of the member 
replaces the base-class version.
 
0
Shiraz Abbas Rizvi
[STPL]
 
 
Question
What is command routing in MFC
Rank Answer Posted By  
 Question Submitted By :: Varaprasadk
This Interview Question Asked @   GE
I also faced this Question!!   © ALL Interview .com
Answer
Check the Command pattern in Gof books, MFC almost use it in
the same way:
SubWidget in the dialog will catch it firstly, it will
forward it to Parent window(the dialog) if *request is not
for it or no handler defined. 

This procedure runs recursively, until one handle it or pass
it to application object. Application will omit unknown
command by default
 
0
Bob
 
 
Question
how to overload << and >> operator in c++
Rank Answer Posted By  
 Question Submitted By :: Kumod
This Interview Question Asked @   Wipro
I also faced this Question!!   © ALL Interview .com
Answer
class chocoBox {
private:
    int pieCount;
    float boxPrice;

public:
    // By giving default arguments, const acts like
    // 0, 1 and 2 argument contructor
    myClass(int pCount = 10, float bPrice = 20.0)
        : pieCount(pCount), boxPrice(bPrice)
    { }

    int getPieCount() { return pieCount; }
    float getBoxPrice() { return boxPrice; }
    void setPieCount(int pc) { pieCount = pc; }
    void setBoxPrice(float bp) {boxPrice = bp; }
};

/* Lets overload the operator << of ostream class. We will
   return a reference of ostream class for cascading calls
   e.g. cout<<obj1<<obj2
*/
ostream& operator<< (ostream &stream, const myClass &obj)
{
    stream<<obj.GetPieCount<<" "<<obj.GetBoxPrice<<endl;
    return (stream);
}
 
0
Manav Sharma
 
 
Answer
in c++ << and >> overloaded as the insertion and out put 
symbole
 
0
Abed
 
 
Answer
"<<" this inserssion perrator is used for output the 
messages&values
">>"this exsersition operator is used for input the values
sentax:
   
   return_type operator op(arguments_list)
{
----
----
}
 
0
Ramya
 
 
Question
pointers are support in C#? if yes then how to use it?
Rank Answer Posted By  
 Question Submitted By :: Jkreddy_peram
This Interview Question Asked @   Softvision-Solution
I also faced this Question!!   © ALL Interview .com
Answer
yes
 
0
Varsha Vilas Kalebag
 
 
Answer
yes, pointer is nothing but value is saved in another 
memory address
 
3
Varsha Vilas Kalebag
[Hawkeye Solutions]
 
 
Answer
pointers in C# are considered as unsafe code. We can use 
pointers in the same way as we use in C++ or VC++ but we 
need to build it with a /unsafe option
 
2
Supratim Sengupta
[Hawkeye Solutions]
 
 
Answer
NO
pointer is not used in c#
 
0
Rajiv Grover
[Hawkeye Solutions]
 
 
Answer
ya... pointer can be used in c# for value and array 
types...and in inside class too (but class-> reference type 
so not applicable)in the class members which are not ref 
type../ using fixed keyword ... but it is unsafe....
 
0
Rajavel
[Hawkeye Solutions]
 
 
Question
what is an array
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
array is an set od data types
 
0
Varsha Vilas Kalebag
 
 
Answer
array i s the collection of similar data type it reduces 
the unnecessary decleration of data types or variables 
 
0
Abed
 
 
Answer
array is nothing but an array(a set ) of constants of 
similar data type .
 
3
Venu Gopal Raju
 
 
Answer
an array is a collection of elements of a single data type 
stored in adjacent


<data_type><variable_name>[<dimension_size>];
ex:

int arr[5];
 
0
Nekkanti Rajesh
 
 
Answer
An Array is set of related data items that shares a common 
name.
 
0
Hariharan,k
 
 
Answer
Array is a set of elements with homogeneous(same) data 
type ,that stores elements consecutivly in memory location 
and access of array elements is depending on the position 
of elements in the array.
 
0
Swamy S T
 
 
Answer
An Array is nothing but a collection of homogenous data of 
fixed type.
 
0
Shankar
 
 
Answer
array is a collection of homogeneous data items,that shares 
a common name,this is stored in sequence memory.
 
0
Malathi
 
 
Answer
array is a collection of elements
 
0
Sivasankar
 
 
Answer
an array is a collection of elements with same data type. 
it can also reduce the storage space
 
0
Saranya
 
 
Answer
Array is a collection of variables of same data type stored 
in contigious memory locations....
 
0
Pradeep.v.s.
 
 
Answer
an array is a FIXED-SIZE sequenced collection of elements
of the same data type
 
0
Chandrakanthvellanki
 
 
Question
what is virtual function?
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   Infosys , Tcs, Hp
I also faced this Question!!   © ALL Interview .com
Answer
The virtual keyword means that method,property or function 
can be overridden
 
1
Jayakrishna Reddy
 
 
Answer
virtual function can be used to override the propertis of a 
function.it is normaly used in inheritance. it is part of  
polymerphism.
 
0
Kumod
 
 
Answer
virtual function is ended with null 

virtual function=o
 
0
Varsha Vilas Kalebag
 
 
Answer
It allows one to write generalized code that works with the 
base class pointer which can dynamically point to the 
derieved class objects. Virtual function allows you to 
implement runtime polymorphism. It allows the function call 
to be binded with function definition as late as runtime.

Also read: concept of VPTR and VTABLE from Thinking in C++
 
4
Manav Sharma
 
 
Answer
When derived class overrides the base class method by 
redefining the same function, then if client wants to 
access redefined the method from derived class through a 
pointer from base class object, then you must define this 
function in base class as virtual function.
 
0
Manab
 
 
Answer
The objects of the polymorphic class, addressed by 
pointers, change at runtime and respond differently for the 
same message.Such mechanism requres postponment of binding 
of a function call to the member function [ VIRTUAL] untill 
runtime.
 
0
Purba Phalguni Mishra, Gandhi
 
 
Answer
A virtual function is a function member of a class, 
declared using the "virtual" keyword. A pointer to a 
derived class object may be assigned to a base class 
pointer, and a virtual function called through the pointer. 
If the function is virtual and occurs both in the base 
class and in derived classes, then the right function will 
be picked up based on what the base class pointer "really" 
points at.
 
0
Aarti Ashar
 
 
Answer
A virtual function is basically a like normal function but 
we can override the function in the derived classes.
Now when we want to access like (fn)

Base * bptr = new Derived();
bptr->fn(); then function of the derived class will be 
called only if the function is marked as virtual in the 
base class.

i.e the virtual keywork tells to use the function of the 
class to which it is pointing to and not to the Base class. 
This is called runtime polymorphism.
 
0
Nk
 
 
Answer
The virtual function is nothing but the function in the 
base class with the virtual keyword, that allows us to 
derive only once in the class which is going to accsess it 
while it is the child of two different classes which are 
the child of the same base class.This is nothing but the 
dynamic binding.
 
0
Gomathisivaram
 
 
Answer
A virtual function is a function which is precedded by the 
key word derived is declared in the base class.It is 
normally used to achieve run time polymerphism.That means 
we can override the base class function in the derived 
class.We can invoke the virtual function through the base 
class pointer depending upon the contents to which the base 
class pointer points to.
               Generally the implementation of virtual 
class was found in inheritance where the base class 
function is override in the derived class.
 
0
Laxmikant
 
 
Answer
virtual function is used to prevent from more times 
calling.That means if a function is declared as virtual 
then its def will be diferent in base class & derived class
 
0
Susanta Samal
 
 
Question
Difference between over loading and over ridding? 
Rank Answer Posted By  
 Question Submitted By :: Sanglap
This Interview Question Asked @   CTS , Patni, Softvision Solution, Patni
I also faced this Question!!   © ALL Interview .com
Answer
overloading means when you define more than one function 
with the same name but different with its signature.


over ridding means give the modified defination of the 
inherited functions or methods.
 
1
Azhar Iqbal
 
 
Answer
Overloading is nothing but compile time allocation where we 
will come to know which method will be called. In this 
method we can overload either a method or even operators 
too.

Overridding is nothing but run time allocation. We being 
programmers can let the program to deside which method 
should be called during the execution.  During comp time, 
we will never come to know which object will call which 
method. This can be achived by using VIRTUAL keyword.
 
0
Shashikanth C R
[None]
 
 
Answer
Overloading: Same function or operator responds differently 
on different types on inputs. This is done by defining a 
function (including operator fn() definition) with the same 
name but different argument list.

Overriding: Redefining any base class function in a 
derieved class to work differently than what is defined in 
the base class. So, now the same function called with same 
argument list will behave differently when called on the 
objects of base and derieved class.

Important: Which instance of function to bind with the 
object depends on the type of object on which the function 
is called and is decided on compile time. This is also 
called early binding or compile time polymorphism.
 
0
Manav Sharma
[None]
 
 
Answer
over loading is nothing but
 
0
Varsha Vilas Kalebag
[None]
 
 
Answer
overloading means one function name havimg different 
arguements.
but overriding means the base as well as the derived class 
havimg same function name
 
0
Srabani
[None]
 
 
Answer
Overloading means when we write diffrent fun. With the Same name & with diffrent singnature then it is called  overloading .     Overiding means both base & derived class has same name.
 
0
Amit,mumbai
[None]
 
 
Answer
Overloading:-Writing Two or three methods with same name 
but different parameters in same class,it is called 
methodOverloading.

Overriding:-writing same methodname and parameters in 
subclass and superclass with same return  type,it is called 
methodoverriding.
 
0
Nagababu
[None]
 
 
Answer
Difference

Method OverLoading
1. Same method name with different number of argument
2. Number of argument with different datatype
3. Each method may returns different type of value
4. All overloaded methods founds to be in one class.

Method OverRiding
1. Same method name with same number of argument
2. Number of argument with same datatype
3. Each method must returns same type of value
4. Each overrided method of base class founds in respective 
derived class.
 
0
Rameshwar Gaikwad
[None]
 
 
Answer
over loading : diff functns hvng same name are invoked
during the program whnever required by the programmer.

over ridding : gvs modified defination 2 d functns
 
0
Imlepakshi
[None]
 
 
Answer
Method Overloading is the method name looks similar but 
return type and method arguement (inside parameter) differs.

Method Overiding is that the method name, arguements and 
return type seems similar on both base and derived class. 
(Sometimes we will add the additional code to the derived 
class method also).
 
0
Vasanth
[None]
 
 
Question
how to create thread in java?
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   Infosys
I also faced this Question!!   © ALL Interview .com
Answer
There are two methods available
1.by using extends keyword
2.by using interfaces
 
0
Guest
 
 
Answer
It was created by extended from Thread class
and also we can create from interface  thred
 
0
Solanki
 
 
Answer
by extending thread class or by implementing runnable 
interface
 
0
Mohan
 
 
Answer
Their are specifically two different approaches to create 
threads in Java:
1.By Extending thread class.
2.By Implementing runnable interface.
 
0
Bijoy
 
 
Answer
It can also be created in number of ways.
1.Extended threadclass
2.Running thread
 
0
Hari
 
 
Answer
we can do it in two ways.
one is by extending thread class and other is by 
implementing Runnable interface.
 here the later one is good because when we are going for 
mutiple inheritance only interface helps us
 
0
Vamsikrishna
 
 
Answer
There is two ways for creating Thread in Java:
1.Extending Thread class

2.Implementing Runnable Interface

Second one is much more benificial than 1st one,as we can 
able to avoid the overriden methods.
 
0
Bijoy Kumar Baral
 
 
Answer
There are two methods to create thread in java :
(1). By extending the Thread class.
(2). By implementing the Runnable interface.
 
0
Rahul Madanan
 
 
Answer
Thread can be created by

1. Extending Thread Class
2. implementing Runnable interface

The second approach is better as if you want to use multiple
inheritance, interface is better option.
 
0
Vijay Tandel
 
 
Answer
Thread can be created by tow way
1.interface
2.runnable interface
 
0
Mask
 
 
Question
When a private constructer is being inherited from one 
class to another class and when the object is instantiated 
is the space reserved for this private variable in the 
memory??
Rank Answer Posted By  
 Question Submitted By :: Neha
This Interview Question Asked @   Honeywell , Honeywell, HCL
I also faced this Question!!   © ALL Interview .com
Answer
constructors can not be inherited!
bcoz their work is to initialise the object of the class to 
which they belong to!
so if they get inherited,how can they initialise the object 
of the derived class!
 
0
Uttama
 
 
Answer
yes
 
0
Varsha Vilas Kalebag
 
 
Answer
yes.
 
0
Vatsa
 
 
Answer
How do u expect a private part of a class to be inheritable
Do u have any code to support your views
I am ready to solve the same
 
3
Kamlesh
 
 
Answer
The question is very absurd. From where did we get the 
variable stuff? And ya, how on earth do we get private 
members/functions being inherited? Kamlesh is right in 
saying that The whole idea stinks.
 
0
Karandeep Malik
 
 
Answer
before invoking derived class constructor base-class 
constructor should be called.
1. first base-class object will be created then derived-
class object will be created. 
2. here the base class constructor is private, so derived-
class cannot invoke it.

 No object is created in derived-class.
 
0
Balakishore
 
 
Answer
Private Constructor is not inherited.
When private member varible is not inherited but the size is
occupid in dervied class object.

e.g. 
#include <iostream.h>
class A
{
   int x;
   int y;
};

class B : private A
{
};

int main()
{ 
   cout << sizeof(B);
}

output :
8
 
0
Sanjay Makwana, Puna
 
 
Answer
Neha, your question is not proper, please edit that. Some 
where inheritance of private constructor and some where 
private variable.
Please edit it so that people can help you.
 
0
Reejusri
 
 
Answer
When a constructor is made private, object of that class 
can not be created. That is called as Abstract class.  
constructors can not be inherited. Moreover, when this 
class is inherited, the base class object can not be 
created. So we can not create the derived class object 
also.
 
0
Veena
 
 
Answer
When a constructor is made private, object of that class 
can not be created. That is called as Abstract class.  
constructors can not be inherited. Moreover, when this 
class is inherited, the base class object can not be 
created. So we can not create the derived class object 
also.



the above ans is irrelevant to the current situation,
here the thing is, a constructor cannot b private coz there
is no use of .

but if a situation occurs as such in the given prob, yes the
space is reserved for that useless private constructor.
 
0
Sillu Nu Oru C Coder
 
 
Answer
constructors cannot be private.
 
0
Nk
 
 
Answer
public class TrialClass
{
    protected int i, j;
    public TrialClass(int one, int two)
	{
        i = one;
        j = two;
	}
    public TrialClass(int joo)
    {

    }
    public int squareArea()
    {
        int side1;
        int side2;
        side1 = i;
        side2 = j;
        return side1 * side2;
    }
    
}
public class myDerivedClass : TrialClass

{
     int rd;
     int dr;
    public myDerivedClass(int Age, int ages):base(Age)
    {
        rd = ages;
        dr = Age;    
    }
    
} 

Try making the base class single parameterized constructor
private.You will get your answer.
 
0
Ankur Sehgal
 
 
Question
c# support late binding or early binding.
Rank Answer Posted By  
 Question Submitted By :: Raj
I also faced this Question!!   © ALL Interview .com
Answer
yes c# support late binding or early binding
 
0
Babu Khatri Bhai
 
 
Answer
yes it supports both depends
 
0
Rakesh
 
 
Answer
Early binding is when your client app can detect at compile 
time what object a property or method belongs to. Since 
it "knows", it resolves the references and the compiled 
executable contains only the code to invoke the object's 
properties, methods, events, etc. 

This is a good thing if you want to speed because the call 
overhead is greatly reduced. 

Late binding is the slowest way to invoke the properties 
and methods of an object. You use late binding when you 
write a function that uses an object variable that acts on 
any of several different class objects. Since the compiler 
doesn't "know" what class object will be assigned to the 
variable, it doesn't resolve the references into the 
compiled executable. In this case they are resolved at 
runtime... when you actually have an assigned object to 
reference the properties and methods to. 

Hope this helps.
 
0
Santu Sarkar
 
 
Question
Give the output of the following program
main()
{int ret;
ret=fork();ret=fork();ret=fork();ret=fork();
if(!ret)
printf("sun");
else
printf("solaris");
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   Sun-Microsystems
I also faced this Question!!   © ALL Interview .com
Answer
sunsolarissunsolarissunsolarissunsol
 
0
Tajul Bashar
 
 
Answer
I dont't think this will compile as its missing a closing 
brace.
 
0
Imran
 
 
Answer
It depends on the return value of fork(). If it is other 
than 0 (zero), then the output is solaris else sun.
 
2
Pdp
 
 
Answer
Imagining that the correct headers were included and the
closing bracket for the main function is added, it'll print
sun 8 times and solaris 8 times. You won't know the order
that they're printed in, it depends on the kernel scheduler
as to which process is run first.
 
0
Rojoco
 </