Qbasicnews.com

Full Version: why?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I´m currently playing around with function to learn how to use them.

I wounder why I get a real strange number (13451318)
when I do:


Code:
# include <stdio.h>

int funktion (int y ,int x);

main ()
{
int i=40;
int k=50;
funktion (k,i);
printf("%d",funktion);
}

int funkktion (int y , int x){
int o = y+x;
return o;
}


*is really confused*
*figurs he probably made a real newbie mistake*
It is printing the value of function, which is a pointer so that's why you got that number. You could have done it in two ways:

1

Code:
# include <stdio.h>

int funktion (int y ,int x);

main ()
{
   int i=40;
   int k=50;
   int result;

   result = funktion (k,i);
   printf("%d", result);
}

int funkktion (int y , int x){
   int o = y+x;
   return o;
}

2

Code:
# include <stdio.h>

int funktion (int y ,int x);

main ()
{
   int i=40;
   int k=50;
  
   printf("%d", funktion (k,i) );
}

int funkktion (int y , int x){
   int o = y+x;
   return o;
}

You have to use the function's return value, wheter assigning it to a variable or using it directly in printf.
oh I see thx a ton for the help.