Skip to content

Instantly share code, notes, and snippets.

@Silva97
Created June 4, 2019 02:04
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 Silva97/ae7a0d6ea37e7f81b7223ca7bc2bc379 to your computer and use it in GitHub Desktop.
Save Silva97/ae7a0d6ea37e7f81b7223ca7bc2bc379 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct test {
char str[10];
int n;
};
void edit(struct test *);
int main(void)
{
struct test example = {
.str = "Hello",
.n = 5
};
struct test *example_ptr = malloc(sizeof(struct test));
strcpy(example_ptr->str, "Hello2");
example_ptr->n = 6;
edit(&example);
edit(example_ptr);
printf("str: %s\n"
"n: %d\n",
example.str,
example.n);
printf("str: %s\n"
"n: %d\n",
example_ptr->str,
example_ptr->n);
return 0;
}
void edit(struct test *src)
{
*src->str = 'R';
src->n = 10;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment