we all know about the function overloading concept used in
C++ and we all learnt abt that.... but that concept is
already came in C in a very smaller propotion ... my
question is IN WHICH CONCEPT THERE IS A USE OF FUNCTION
OVERLOADING IS USED in C language?????????????
Answer Posted / sandeep
Function Overloading or Polymorphic Behaviour for C
functions can be seen for those functions who accept
variable number of arguments.
They can take any number of arguments and any type of
arguments, its upon the programmer or the code inside it,
that decides what it wants those arguments to be , int ,
char ,float or something else..
ALthough it is not seperate function that runs for different
number and types of arguments, still for the user, a
function will be provided for different types of list of
input parameters, all being sent to the same ('name of the
')function..
#include <stdarg.h>
enum data_type{ TYPE_INT=0,TYPE_STRING=1};
int max( int num_of_arguments,...)
{
va_list arg_list;
va_start(arg_list, num_of_arguments);
data_type type=va_arg(arg_list,data_type);
if(type=TYPE_INT)
{
int max =0,i;
for(i = 2; i <= num_of_arguments; i++)
{
if((a = va_arg(arg_list, int)) > max)
max = a;
}
}
else
{
//do whaterver..
}
va_end(arg_list);
}
| Is This Answer Correct ? | 10 Yes | 2 No |
Post New Answer View All Answers
Why is c not oop?
how many key words availabel in c a) 28 b) 31 c) 32
How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?
Which one would you prefer - a macro or a function?
Why malloc is faster than calloc?
Can we increase size of array in c?
‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.
Is it possible to execute code even after the program exits the main() function?
In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between 1 and N.Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.
Why is it that not all header files are declared in every C program?
What is function prototype in c language?
How can you allocate arrays or structures bigger than 64K?
What are pointers? What are different types of pointers?
What is pointer to pointer in c?
Explain a pre-processor and its advantages.