Being fairly new with C but having a strong Java/C# background, I'd like to "test" out what pointers are all good for.
I've explained my question via some comments inside my code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
// Some start value:
int speed = 88;
typedef struct {
int *speed; // Reference to the other speed variable.
} Motor;
// Create a "new" motor:
Motor a;
// "Link" the speed variables to each other:
a.speed = &speed;
// Now I'd like both a.speed and speed to be equal to "100".
a.speed = 100;
// Simple test, result wanted: 100 100, result achieved: 100 88.
printf("%i %i\n", speed, a.speed);
system("PAUSE");
return 0;
}
So, is it even possible to "assign by reference"? I understand why my above example doesn't work - but would like to know if it is possible at all.
- Gerard