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?????????????
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / vaidyanathan
Hi,MY name is vaidyanathan....and and we have used such type of concepts in the recursion..
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / rohit
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);
}
In c we are not allowed to function overloading with
parameters wherever we like.
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / venkatesh
In c also we are allowed to function overloading with
parameters wherever we like.
| Is This Answer Correct ? | 0 Yes | 6 No |
Differentiate between #include<...> and #include '...'
6. Which of the Following is not defined in string.h? A)strspn() B)strerror() C)memchr() D)strod()
What is the meaning of int *x[]();?
write a own function to compare two strings with out using stringcomparition function?
int a=1,b=2,c=3; printf("%d,%d",a,b,c); What is the output?
WHAT IS ABSTRACT DATA TYPE
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
what is the use of keyword volatile??
Is that possible to store 32768 in an int data type variable?
What are shell structures used for?
implement NAND gate logic in C code without using any bitwise operatior.
mplementation of stack using any programing language