Can anybody explain why
all_leds[0].pattern = 3;
and
all_leds[1].pattern = 4;
do nothing ?
#include <stdio.h>
int main(void)
{
struct Led
{
int pin;
int pattern;
};
struct Led led_1 = {1, 1};
struct Led led_2 = {2, 2};
printf("%d\n", led_1.pattern); // prints 1
printf("%d\n", led_2.pattern); // prints 2
struct Led all_leds[2];
all_leds[0] = led_1;
all_leds[1] = led_2;
printf("%d\n", led_1.pattern); // prints 1
printf("%d\n", led_2.pattern); // prints 2
all_leds[0].pattern = 3;
all_leds[1].pattern = 4;
printf("%d\n", led_1.pattern); // prints 1 ????
printf("%d\n", led_2.pattern); // prints 2 ????
return 0;
}
all_leds[0].patternand printingled_1.patternthose are two different memory spaces...a = b;meansahas the same value asb, it does not mean that they both refer to the same object.