1
C / C++ /C# / Re: [C] Pointers and Structs
« on: February 20, 2011 »
Happy days, I resolved the issue.
This is the working variant, if someone runs into the same issue:
Notice how I use the "star symbol" in both the "*a.speed = 70" and the "printf()" statements.
This is the working variant, if someone runs into the same issue:
Code: [Select]
#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 = 77;
// Simple test, Result wanted: 100 100, result achieved 100 88
printf("%i %i\n", speed, *a.speed);
system("PAUSE");
return 0;
}Notice how I use the "star symbol" in both the "*a.speed = 70" and the "printf()" statements.