Skip to content

Instantly share code, notes, and snippets.

@kilroyjones
Created March 23, 2024 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kilroyjones/8fee9ff87a34a2e05eb5b1107ec44127 to your computer and use it in GitHub Desktop.
Save kilroyjones/8fee9ff87a34a2e05eb5b1107ec44127 to your computer and use it in GitHub Desktop.
// Example in posts on Rust borrow system
#include <stdio.h>
typedef struct {
int age;
int is_oldest;
} Person;
int main() {
Person people[] = {
{10, 0},
{8, 0},
{14, 0}
};
int length = sizeof(people) / sizeof(people[0]);
Person *oldest = &people[0];
for (int i = 1; i < length; i++) {
if (people[i].age > oldest->age) {
oldest = &people[i];
}
}
oldest->is_oldest = 1;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment