What is function overloading and operator overloading?
Answers were Sorted based on User's Feedback
Answer / jerry
function overloading - function name will be same but
operation will be different for eg:
if we take the function as area
then 1. area(int x,int y)
2. area(int x);
these r the two functions with the same name but
they will differ by their arguments given
for the 1st function
it becomes the area of the rectangle=x*y
for the 2nd function it becomes the area of square=x*x
coming to the operator overloading,
it is an overloading function of an operator.
if we + as an operator
a+b then + is operator for the operands a,b
c+d then + is also an poperator for the c,b.
these r the two properties of polymorphism.
Is This Answer Correct ? | 53 Yes | 12 No |
Answer / manjeetsheoran
we can use the same function name but function signature are
differnt is called function overloading
for example
niit(int a int b)
niit(int a string name)
Is This Answer Correct ? | 10 Yes | 2 No |
Answer / sagar sapkota
A function is overloaded when same name is given to different function. However, the two functions with the same name will differ at least in one of the following.
a) The number of parameters
b) The data type of parameters
c) The order of appearance
These three together are referred to as the function signature.
For example if we have two functions :
void foo(int i,char a);
void boo(int j,char b);
Their signature is the same (int ,char) but a function
void moo(int i,int j) ; has a signature (int, int) which is different
While overloading a function, the return type of the functions need to be the same.
In general functions are overloaded when :
1. Functions differ in function signature.
2. Return type of the functions is the same.
Operator overloading allows existing C++ operators to be redefined so that they work on objects of user-defined classes. Overloaded operators are syntactic sugar for equivalent function calls. They form a pleasant facade that doesn't add anything fundamental to the language (but they can improve understandability and reduce maintenance costs).
Is This Answer Correct ? | 8 Yes | 2 No |
Answer / jha
Both function overloading and operator overloading is same
thing we can reuse the thing. In operator overloading we
can reuse the operator and user can work through object;
In function overloading we can overloading the same method
in derived class.
Is This Answer Correct ? | 28 Yes | 36 No |
What is function overloading?,describe it with the example.
#include <string.h> #include <stdio.h> #include <stdlib.h> #include <conio.h> void select(char *items, int count); int main(void) { char s[255]; printf("Enter a string:"); gets(s); select(s, strlen(s)); printf("The sorted string is: %s.\n", s); getch(); return 0; } void select(char *items, int count) { register int a, b, c; int exchange; char t; for(a = 0; a < count-1; ++a) { exchange = 0; c = a; t = items[ a ]; for(b = a + 1; b < count; ++b) { if(items[ b ] < t) { c = b; t = items[ b ]; exchange = 1; } } if(exchange) { items[ c ] = items[ a ]; items[ a ] = t; } } } design an algorithm for Selection Sort
what is virtual function in c++
why c++ is called OOPS? waht is inherutance? what is compiler?
What is difference between polymorphism and inheritance?
Can we create object of interface?
if i have same function with same number of argument but defined in different files. Now i am adding these two files in a third file and calling this function . which will get called and wht decide the precedence?
What is the differances between a abstract calss and interface
What is encapsulation process?
What is encapsulation?
Which is the best institute in hyderabad for C/C++ and it also has fast track course structure.
Why is destructor used?