Code:
//write in C this example
#include <stdio.h>
#include <stdlib.h>
//function to double the value
void doublemynum(int *num_pointer) // (*num_pointer) gets the contents of num which is pointed to by the pointer
{
(*num_pointer) = (*num_pointer) * 2;
//return *num_pointer;
}
int main(void)
{
int num = 10;
printf("The original value is %i\n",num);
printf("The new doubled value is %i ",doublemynum(&num));
return 0;
}
hi, thanks for the reply, but should it be
Code:
printf("The new doubled value is %i ", doublemynum(&num));
instead of
printf("The new doubled value is %i ", doublemynum(num));
because we need to reference the location for the variable num?
But i have tried either way and there is a error saying "void value not ignored as it ought to be" why is this so?
Lastly, do we have to put the return *num_pointer in the function??
sorry i am getting used to the ideology of using pointers...