Skip to content

Instantly share code, notes, and snippets.

@teamdandelion
Created April 20, 2015 19:22
Show Gist options
  • Save teamdandelion/a6559bf5fcaae4b2ba32 to your computer and use it in GitHub Desktop.
Save teamdandelion/a6559bf5fcaae4b2ba32 to your computer and use it in GitHub Desktop.
c-onfusion
#define BUFFER_SIZE 4
struct message {
int content;
};
struct message buffer[BUFFER_SIZE];
int main() {
int i;
printf("allocated buffer, have done nothing with it");
printBuffer();
for (i=0; i<BUFFER_SIZE; i++) {
struct message m = buffer[i];
m.content = 99;
}
printf("assignment sequence 1");
printBuffer();
for (i=0; i<BUFFER_SIZE; i++) {
buffer[i].content = 99;
}
printf("assignment sequence 2");
printBuffer();
}
output from running this program:
>>>allocated buffer, have done nothing with it[0,0,0,0,]
>>>assignment sequence 1[0,0,0,0,]
>>>assignment sequence 2[99,99,99,99,]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment