GeekInterview.com
Series: Subject: Topic:
Question: 154 of 238

TCS C/C++ Questions

1. Difference between "C structure" and "C++ structure".
2. Diffrence between a "assignment operator" and a "copy constructor"
3. What is the difference between "overloading" and "overridding"?
4. Explain the need for "Virtual Destructor".
5. Can we have "Virtual Constructors"?
6. What are the different types of polymorphism?
7. What are Virtual Functions? How to implement virtual functions in "C"
8. What are the different types of Storage classes?
9. What is Namespace?
10. What are the types of STL containers?.
11. Difference between "vector" and "array"?
12. How to write a program such that it will delete itself after exectution?
13. Can we generate a C++ source code from the binary file?
14. What are inline functions?
15. What is "strstream" ?
16. Explain "passing by value", "passing by pointer" and "passing by reference"
17. Have you heard of "mutable" keyword?
18. What is a "RTTI"?
19. Is there something that I can do in C and not in C++?
20. What is the difference between "calloc" and "malloc"?
21. What will happen if I allocate memory using "new" and free it using "free" or allocate using "calloc" and free it using "delete"?
22. Difference between "printf" and "sprintf".
23. What is "map" in STL?
24. When shall I use Multiple Inheritance?
25. Explain working of printf.
26. Talk sometiming about profiling?
27. How many lines of code you have written for a single program?
28. How to write Multithreaded applications using C++?
29. Write any small program that will compile in "C" but not in "C++"
30. What is Memory Alignment?
31. Why preincrement operator is faster than postincrement?
32. What are the techniques you use for debugging?
33. How to reduce a final size of executable?
34. Give 2 examples of a code optimization.
This question is related to TCS Interview
Asked by: Interview Candidate | Asked on: Sep 15th, 2005

Editorial / Best Answer

Answered by: Rajini

Answered On : Feb 19th, 2007

Q. Difference between "C structure" and "C++ structure".
Ans:- C structure cannot have member functions but C++ structure can have. Also in a C structure by default all data members of structure are public and access cannot be changed by specifying the private or protected keywords but in C++ eventhough by default members are public we may change the access using the keywords private and protected.
Q. What is the difference between "overloading" and "overridding"?
ans:- Overloading is a process of having the same function name but different no of arguments or types of arguments within the same class but overriding means redefining a baseclass functions definition in the subclass.
Q. Explain the need for "Virtual Destructor".
Ans:=Virtual destructor ensures destruction of subclass and base class objects in proper order.
Q. What are the different types of polymorphism?
Ans:-Overloading and overriding.
Q. What are the different types of Storage classes?
ans:-Auto,Register,static and extern
Q. What is the difference between "calloc" and "malloc"?
Ans:- calloc and malloc are used for dynamic memory allocation. Calloc initializes the memory locations to zero by default but malloc memory contains garbage values.
Difference between "printf" and "sprintf".
printf will write to the console. sprintf will write to the buffer

Showing Answers 1 - 12 of 12 Answers
Angayarkanni.M

Answered On : Mar 3rd, 2006

Assignment Operator:

         The Assignment operator simply assigns the value of the expression found in the right hand side.

  Syntax : variable = expression;

Copy Constructor:

         The copy constructor copies the data values from one object to another object.When we use statements like c1 = c2 where c2 & c1 are the objects of a class,the c++ compiler implicitly creates a copy constructor and copy the values of c2 to c1.we may also invoke the copy constructor as follows:  classname objectname1(objectname2);

Yes  1 User has rated as useful.
  
Login to rate this answer.
navinece

Answered On : May 4th, 2006

View all answers by navinece

What is map in stl

  
Login to rate this answer.
ASHOK SRIVASTAVA

Answered On : May 17th, 2006

Excellent

  
Login to rate this answer.
sujith kurian

Answered On : May 20th, 2006

No other words.... Only thanks a lot......

  
Login to rate this answer.
pavankishore

Answered On : Nov 28th, 2006


Re:3rd question

Overloading means the ability to have more than one form.this is also called polymorphism.

it maybe method or operator overloading.

Overriding occurs when we have same method in both subclass and superclass

 

  
Login to rate this answer.
pavankishore

Answered On : Nov 28th, 2006

Re:6th Question:

polymorphism exhibits in two cases

1:method polymorphism.

2:operator polymorphism.

in method polymorphism we have same methods more than once  in the same class.

in operator polymorphism we have more than one meaning to an operator.

  
Login to rate this answer.
asheesh

Answered On : Dec 12th, 2006

maps are data structures containing two entities index and dataindex->data

  
Login to rate this answer.
Rajini

Answered On : Feb 19th, 2007

Q. Difference between "C structure" and "C++ structure".
Ans:- C structure cannot have member functions but C++ structure can have. Also in a C structure by default all data members of structure are public and access cannot be changed by specifying the private or protected keywords but in C++ eventhough by default members are public we may change the access using the keywords private and protected.
Q. What is the difference between "overloading" and "overridding"?
ans:- Overloading is a process of having the same function name but different no of arguments or types of arguments within the same class but overriding means redefining a baseclass functions definition in the subclass.
Q. Explain the need for "Virtual Destructor".
Ans:=Virtual destructor ensures destruction of subclass and base class objects in proper order.
Q. What are the different types of polymorphism?
Ans:-Overloading and overriding.
Q. What are the different types of Storage classes?
ans:-Auto,Register,static and extern
Q. What is the difference between "calloc" and "malloc"?
Ans:- calloc and malloc are used for dynamic memory allocation. Calloc initializes the memory locations to zero by default but malloc memory contains garbage values.
Difference between "printf" and "sprintf".
printf will write to the console. sprintf will write to the buffer

Yes  5 Users have rated as useful.
  
Login to rate this answer.
SuganV7

Answered On : Feb 19th, 2007

we  should not let the compiler's  copyconstructor to do the task,

By default the copy constructor and assignment operator are making so-called shallow copies of the object meaning that all of the member values will be copied. This works well if the members are values, but causes problems for members which actually points to dynamically allocated memory. The pointer will be copied - but not the memory it points to...this will result in having both members pointing to the same dynamically allocated memory.

Therefore, if you have a class with dynamic memory allocation a deep copy is required to guarantee that all members gets copied properly. To make a deep copy, you must write a copy constructor and overload the assignment operator.

class CFoo()
{
public:
// Constructor
CFoo() { m_pArray = new char[100]; }

// Destructor
~CFoo() { delete [] m_pArray; }

// Copy constructor
CFoo(const CFoo &refcSource)
{
// Allocate new space
m_pArray = new char[strlen(refcSource.m_pArray) + 1];

// Copy values
strcpy(m_pArray, refcSource.m_pArray);
}

// Assignment operator
CFoo& operator=(const CFoo &refcSource)
{
// Check whether it is the same instance
if(&refcSource != this)
{
// Release old memory
delete [] m_pArray;

// Allocate new space
m_pArray = new char[strlen(refcSource.m_pArray) + 1];

// Copy values
strcpy(m_pArray, refcSource.m_pArray);
}

return *this;
}

private:
char *m_pArray;
};

Yes  1 User has rated as useful.
  
Login to rate this answer.
Vikas Pachauri

Answered On : May 16th, 2007



Assignment Operator is an operator which simply assign the value of right hand side object to left hand side object. Like int a=3; int b=a; then the value of b will be 3 But in case of array and objects say if we have two objects C1 and C2 then C1=C2 will copy the address of C2 into C1 thus we can access the same memory location with the other name.

 But in case of Copy Constructor it creates the new object and copy the values of all element in the previous object to the new object or we can say to the new memory location.

Note if we use assignment operator at the time of declaring an object it behaves like a copy constructor. say   object C1= C2 it will call copy constructor implicitly.



Yes  2 Users have rated as useful.
  
Login to rate this answer.
arun kumar

Answered On : Sep 28th, 2007

Copy constructor can copy all values of the variable of an object to another object.

But an assignment operator is used to initialise a variable.

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.