Skip to content

Instantly share code, notes, and snippets.

@LambdaSix
Last active December 10, 2015 21:28
Show Gist options
  • Save LambdaSix/4494795 to your computer and use it in GitHub Desktop.
Save LambdaSix/4494795 to your computer and use it in GitHub Desktop.
Struct assignment.
$ gcc struct.c -o struct
$ ./struct
a.Bar: 1
b.Bar: 2
a.Bar: 2
b.Bar: 1
#include "stdio.h"
typedef struct Foo {
int Bar;
} Foo;
int main(int argc, char* argv[])
{
// Init them. Plus c as a swap buffer.
Foo a,b,c;
a.Bar = 1;
b.Bar = 2;
printf("a.Bar: %d\n", a.Bar);
printf("b.Bar: %d\n", b.Bar);
// Flip them.
c = a;
a = b;
b = c;
printf("a.Bar: %d\n", a.Bar);
printf("b.Bar: %d\n", b.Bar);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment