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       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories >> Software >> Programming-Languages >> C++
 
  STL (45)  OOPS (186)  C++-General (222)
 


 

Back to Questions Page
 
Question
WHY  FUCTION OVERLOADING DOSENOT RETURN  A RETEN TYPE
Rank Answer Posted By  
 Question Submitted By :: Ashis
I also faced this Question!!   © ALL Interview .com
Answer
Function overloading has a return type...

Ex:
#include<iostream>
using namespace std;
//Function 1:

int max(int a, int b)
{
   return (a>b)? a:b;
}

//Function 2:

float max(float a, float b)
{
   return(a>b)? a:b;
}

int main()
{
   int c;
   float d;
   c=max(5,4);        //will display 5
   cout<<c<<endl;
   d=max(3.14,6.15);  //will display 6.15
   cout<<d<<endl;
   return 0;
}

Important Concepts in Fn. Overloading:
a) Fun Overloading depends upon the type/number/order in 
which the arguments are passed...
b) Fun Overloading can take place for a function which is 
within the same scope... (i.e.) both function 1:, and 
Function 2: should be in the same { ...} (both the 
functions are within main() (i.e. same scope)...
 
0
Manjunathtek
 
 
Question
WHEN A COPY CONSTER IS CALL ?
Rank Answer Posted By  
 Question Submitted By :: Ashis
I also faced this Question!!   © ALL Interview .com
Answer
emp e;//default constr
emp e(10);//paramatrisized constr
emp e(e1);//copy constr

 
0
Muthu_tek
 
 
Question
what is a virtual class?
Rank Answer Posted By  
 Question Submitted By :: Abhijit
This Interview Question Asked @   Cap-Gemini , Ibm
I also faced this Question!!   © ALL Interview .com
Answer
In multiple inheritance when a class D is derived by two 
base classes B and C and both base class is also inherite 
by same class A then then class D will get duplicate copy 
of uppper most base class A.In this case class A will 
declare as virtual class
 
0
Raj
 
 
 
Question
what are the disadvantages of C++?
Rank Answer Posted By  
 Question Submitted By :: Vardhan
This Interview Question Asked @   ATS , Infosys, Jdflvier
I also faced this Question!!   © ALL Interview .com
Answer
persistance
 
0
Mandoos
 
 
Answer
it's not pure object oriented programming language. Because 
c++ doesn't support for garbage collection...Which is a 
disadvantage of C++. Which is overcome by java.
 
0
Ranjan
 
 
Answer
it is not pure object oriented language.
 
0
Rajesh Patil
 
 
Answer
Well, there are many. A few to mention:
* Does not provide very strong type-checking. c++ code is 
easily prone to errors related to data types, their 
conversions, for example, while passing arguments to 
functions.
* Does not provide efficient means for garbage collection, 
as already mentioned.
* No built in support for threads.
* Gets complex when u want to develop a graphics rich 
application in c++
* portability of code on various platforms, etc
 
0
Kanthi
 
 
Question
In what situation factory design patterns,DAO design
patterns,singleton design patterns should be applied.?
Rank Answer Posted By  
 Question Submitted By :: Rakesh
I also faced this Question!!   © ALL Interview .com
Answer
Use Factory Design Pattern when
- a class cannot anticipate the class of objects it must 
create
- a class wants its subclasses to specify the objects it 
creates
- classes delegate the responsibility to one of several 
helper subclasses and you want to knowledge of which helper 
subclass is the delegate.

Use Singleton Pattern when
- there must be one instance of a class and it must be 
accessible to clients from well known access point.
-the sole instance should be extensible by subclassing, and 
client should be able to use an extended instance without 
modifying their code.
 
0
Monica
 
 
Question
what is the size of this class
class size
{
public:
	char data1;
	double d;
	int data2;
	char data3;
	double data4;
	short data5;
};

please explain the padding for these double variables.
Rank Answer Posted By  
 Question Submitted By :: Tarun
I also faced this Question!!   © ALL Interview .com
Answer
double will occupies 8 bytes. so here two double data type 
variables create then this class size is 21

char    1 b
double  8 b
int     2 b
char    1 b
double  2 b
short   1 b
 
0
Nomesh
 
 
Answer
This size is 32

Char : 1 + 3 bytes padding
Doube : 8 Bytes
int   : 4 bytes 
char  : 1 + 3 bytes padding
double : 8 bytes
short : 4 bytes

so 32 bits
 
0
Nivvy
 
 
Answer
absolutely correct navvy agreed !!

just a minor change 

short : 2  bytes + 2 byte padding
 
0
Abhishek
 
 
Answer
22
 
0
Lakshmi Sahu
 
 
Answer
I have a small doubt.. isnt it based upon the underlying 
platform on which this piece of code is run?
as far as my c++ knowledge goes, the size of each datatype 
varies for each platform unlike java. this is the reason 
why java ensures portability of code, while c++ doesnt.
please tell me if i am wrong...
 
0
Kanthi
 
 
Answer
Just as an extension to my point in the previous post... 
http://www.cplusplus.com/doc/tutorial/variables.html

the section fundamental datatypes in the above article 
substantiates my point...
 
0
Kanthi
 
 
Question
Disadvantages of c++
Rank Answer Posted By  
 Question Submitted By :: Vishnu948923
I also faced this Question!!   © ALL Interview .com
Answer
1.C++ is not a fully object oriended.it is a partial object 
oriended programming.

2.it is also worked without the help of classes and object 
like "C" but java can be only accessed through the 
objects.so,it is fully object oreinted and will provide the 
security.

3."C++" would not provide the full security.
 
0
Geetha
 
 
Answer
its not windows oriented,so it takes a time to coding.
 
0
Manoj Prajapati
[No]
 
 
Answer
C++ compilers usually convert the code to C before
converting to assembly language. So it takes double the work
compared to C code
 
0
Ritchie
[No]
 
 
Question
Consider a c++ template funtion
template<class T>
T& Add(T a, T b){return a+b ;}

if this function is called as
T c = Add("SAM", "SUNG");

what will happen? What is the problem in the template 
declaration/ How to solve the problem.
Rank Answer Posted By  
 Question Submitted By :: Skc
This Interview Question Asked @   Samsung
I also faced this Question!!   © ALL Interview .com
Answer
i will provide error.

declare template function as,
T Add(T a, T b){return a+b ;}
 
0
Prasad
 
 
Answer
There are two things to be considered here.

First, T will be an unknown type in the place where we call 
which gives a compilation error.

Second, if we call like this:

std::string c = Add("SAM", "SUNG"); or,
char* c = Add("SAM", "SUNG"); 

the compiler will convey an error since the arguments to 
Add are interpretted as char pointers. The error may be 
something like, "cannot add two pointers....".
 
0
Mms Zubeir
 
 
Answer
The error is adding Two pointers isn't alowed in C/C++.
The compiler imlicitly treats "SAM" as const char*. We need 
to write a function with "explicit" keyword declaration like

explicit  char * Add (const char* x1, const char* x2) 
{
  // check for null pointers.
  // allocate strlen(x1)+strlen(x2)+1 using malloc 
  // say    char*a1 = malloc...;
  // check if malloc returns null..take corrective actions

  // strcpy (a1, x1);
  // strcat (a1, x2);
  //strcat (a1, '\0');

  return a1; // ask the caller to free the memory allocated
  //  for a1

}

since this function is writen explicit the compiler will 
invoke this function and not call the default template 
function.
this is what appears to me. haven't coded and verified.

// Regards, SADIQ
 
0
Skc
 
 
Answer
1) Compiler will throw the error as C++ doesnt support + 
operator for string. Another point is T c = Add
("SAM","SUNG"), where the function call assign to a 
TEMPLATE object type, it syntactical error.

2)We need to write a seperate add function as given below

char* Add( const char *s1, const char*s2);

This will solve the problem
 
0
Sv
 
 
Question
In a class, there is a reference or pointer of an object of 
another class embedded, and the memory is either allocated 
or assigned to the new object created for this class. In 
the constructor, parameters are passed to initialize the 
data members and the embedded object reference to get 
inialized. What measures or design change should be advised 
for proper destruction and avioding memory leaks, getting 
pointers dangling for the embedded object memory 
allocation? Please suggest.
Rank Answer Posted By  
 Question Submitted By :: Sunil Kumar
This Interview Question Asked @   GE
I also faced this Question!!   © ALL Interview .com
Answer
use copy constructors
 
0
Shanthila
 
 
Answer
The most common design is to delete the object reference in 
the destructor of the contained class. This will not be 
helpful in cases where an exception is thrown.

There are two objects here viz, the container object and 
the embedded object.

If the embedded object construction fails, no problem, it 
will not cause any memory leaks since there will be no 
memory allocated for it.

If the container object construction fails after 
constructing the embedded object, there is a chance of 
memory leak. We can use exception handling mechanism to 
deallocate the object's space.

1. If the embedded object reference is not inside the try 
block, then we can use that reference in the catch block to 
delete in case of exceptions.

2. Suppose the embedded object reference/pointer is local 
to the try block. This time, the reference to it won't be 
available in catch block too. So we will not get a chance 
to destroy it even in catch block also. So we need to keep 
such kind of references in a global variable and will be 
available anywhere in the application. So we can delete the 
object reference safely.
 
0
Mms Zubeir
 
 
Answer
Sorry, there is an error in my above answer. In the first 
statement, it is container class, not contained class.
 
0
Mms Zubeir
 
 
Question
Write a program that read 2o numbers in and array and 
output the second largest number. Can anybody help??
Rank Answer Posted By  
 Question Submitted By :: Doukiks
I also faced this Question!!   © ALL Interview .com
Answer
void main()
{
	int numbers[20];
	int biggest=0, secondBiggest=0;

	for(int index = 0; index < 20; ++index)
	{
		int input;
		cin>>input;

		if(input == biggest)
			continue;
		
		if(input > biggest)
		{
			secondBiggest = biggest;
			biggest = input;
		}
		else if(input > secondBiggest)  
secondBiggest = input;
	}

	cout<<endl<<"Biggest : "<<biggest<<endl<<"Second 
biggest : "<<secondBiggest<<endl;

	getch();
}
 
0
Mms Zubeir
 
 
Answer
ya i above is correct
 
0
Sivaraj
 
 
Question
if i want cin 12345678910 and cout abcdefghij.
so how can i create the program?.
example : if i key in 8910 so the answer is ghij.
Rank Answer Posted By  
 Question Submitted By :: Ss
I also faced this Question!!   © ALL Interview .com
Answer
U can Use switch case for this
 
0
Archana
 
 
Answer
I am roughly writing this code and this can be optimized.

void main()
{
	unsigned int input = 0;
	cin>>input;
	int inputArray[10]; // the integer range can be 0 
to 4294967295.
	char carr[11]; // since the integer limit is 10 
digits for 4 bytes allocation.

	int index = 0;
	while(input > 0)
	{
		inputArray[index] = input % 10;
		input = input / 10;
		++index;
	}
	
	cout<<endl<<"character equivalents: "<<endl;
	for(int i = index-1; i>=0; --i)
	{
		if(inputArray[i] == 0) inputArray[i] = 
10; // to represent 0 = j for our calculation.
		carr[index-i] = 
char_traits<char>::to_int_type ('a') - 1 + inputArray[i];
	
		cout<<endl<<carr[index-i]; // displays the 
output.
	}

        getch();
}
 
0
Mms Zubeir
 
 
Answer
I am roughly writing this code and this can be optimized.

void main()
{
	unsigned int input = 0;
	cin>>input;
	int inputArray[10]; // the integer range can be 0 
to 4294967295.
	char carr[11]; // since the integer limit is 10 
digits for 4 bytes allocation.

	int index = 0;
	while(input > 0)
	{
		inputArray[index] = input % 10;
		input = input / 10;
		++index;
	}
	
	cout<<endl<<"character equivalents: "<<endl;
	for(int i = index-1; i>=0; --i)
	{
		if(inputArray[i] == 0) inputArray[i] = 
10; // to represent 0 = j for our calculation.
		carr[index-i] = 
char_traits<char>::to_int_type ('a') - 1 + inputArray[i];
	
		cout<<endl<<carr[index-i]; // displays the 
output.
	}

        getch();
}
 
0
Mms Zubeir
 
 
Question
i ahve v low % in 12th n BSC which is aroun 50 coz science 
was imposed on me......nw m doin MCA n my aggregate in 
above 74%,what shud i say if asked about low previous 
percentage??????
Rank Answer Posted By  
 Question Submitted By :: Jass
I also faced this Question!!   © ALL Interview .com
Answer
first of all learn proper english please. IF you are not in 
a dang chat room dont use stupid things like "shud" instead 
use the real world
 
0
Kevin
 
 
Answer
Yes, it is an awful habit now-a-days some people are 
following, the reason may be, they assume it is stylish & 
modern ???

No, it is not. Please write in full atleast even if you 
commit mistakes.

Come to your question, I am also an interviewer. Your case 
seems to hold good since you are in an ascending lane.

So you can say that "I committed mistakes in my early 
stages of my academic but I realized and corrected. Hence I 
could able to score good score now. I will keep it up for 
rest of my career..."

How is it?
 
0
Mms Zubeir
 
 
Answer
Please don't be so rude kevin , after all we are human
beings bound to be hurt, just give a polite reply, the way
Zubeir answered was perfect.......
 
0
Bharath
 
 
 
Back to Questions Page
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com