Click here to Skip to main content
15,904,415 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C
/* local variable definition */
int max(int num1, int num2);
 
int main () {

  
  int a = 100;
   int b = 200;
   int ret;
 
   /* calling a function to get max value */
   ret = max(a, b);
 
   printf( "Max value is : %d\n", ret );
 
   return 0;
//error is underdefined reference to max
//1 id returned 1 exit status
}


What I have tried:

/* local variable definition */
int max(int num1, int num2);

int main () {


int a = 100;
int b = 200;
int ret;

/* calling a function to get max value */
ret = max(a, b);

printf( "Max value is : %d\n", ret );

return 0;
//error is underdefined reference to max
//1 id returned 1 exit status
}
Posted
Updated 24-Nov-18 5:08am
v2

#include <stdio.h>

int max(int num1, int num2)
{
   int result;
 
   if (num1 > num2)
      result = num1;
   else
      result = num2;
 
   return result; 
};

int main() {
int a = 100;
int b = 200;
int ret;

/* calling a function to get max value */
ret = max(a, b);

printf( "Max value is : %d\n", ret );

return 0;
}
 
Share this answer
 
v2
max is not a built in function in C - you need to define it yourself.
The simplest way it to add this line just above the main function:
C++
#define max(a, b) (a >= b ? a : b)
 
Share this answer
 
C
#include <stdio.h>

/* max function declaration */
int max(int num1, int num2);

int main ()
{
  int a = 100;
  int b = 200;
  int ret;

  /* calling a function to get max value */
  ret = max(a, b);
  printf( "Max value is : %d\n", ret );

  return 0;
}


/* max function definition */
int max( int num1, int num2)
{
  return num1 > num2 ? num1 : num2;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900