Quote:
|
Originally Posted by Mike
I've never used pointers before really, so could you show an example?
|
here is a very simple example of pointers for you Mike
Code:
#include <stdio.h>
int modifyVariables(int *pB, char *pC, float *pD);
int main()
{
int a;
int b;
char c;
float d;
a = modifyVariables(&b, &c, &d);
printf("%d\n", a); //prints 7
printf("%d\n", b); //prints 6
printf("%c\n", c); //prints g
printf("%2.1f\n", d); //prints 22.1
return 0;
}
int modifyVariables(int *pB, char *pC, float *pD)
{
*pB = 6; //sets int b in main function to 6
*pC = 'g'; //sets char c in main function to g
*pD = 22.1; //sets float d in main function to 22.1
return 7;
}
you can only return one variable from a function how ever by sending pointers to variables you can modify more than one variable without returning the values in a return statement.