Created
June 4, 2019 02:04
-
-
Save Silva97/ae7a0d6ea37e7f81b7223ca7bc2bc379 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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