diff --git a/pointer_fun_again b/pointer_fun_again new file mode 100644 index 0000000..4a8898a Binary files /dev/null and b/pointer_fun_again differ diff --git a/pointer_fun_again.c b/pointer_fun_again.c new file mode 100644 index 0000000..8796a1e --- /dev/null +++ b/pointer_fun_again.c @@ -0,0 +1,45 @@ +#include +#include +#include + +struct PlayStruct { + int int_value; + double double_value; + char* a_string; +}; + +void print_struct(struct PlayStruct ps, struct PlayStruct* pps) { + printf("Values of struct ps: %d, %lf, %s\n", ps.int_value, ps.double_value, ps.a_string); + printf("Values of struct pps: %d, %lf, %s\n", pps->int_value, pps->double_value, pps->a_string); +} + +void change_struct(struct PlayStruct ps, struct PlayStruct* pps) { + struct PlayStruct new_ps = {ps.int_value + 1, ps.double_value * 2, ps.a_string}; + *pps = new_ps; +} + +void print_string(char* string_to_print) { + printf("%s\n", string_to_print); +} + +void change_string(char* string1, char** p_string) { + string1[2] = '\0'; + *p_string[1] = '\0'; +} + +int main(int argc, char* argv[]) { + struct PlayStruct play_struct = {1, 2.0, "3456"}; + struct PlayStruct* play_struct_pointer = &play_struct; + + print_struct(play_struct, play_struct_pointer); + change_struct(play_struct, play_struct_pointer); + //first value gets incremented by 1 & second value gets multiplied by 2 & the string wont be changed + print_struct(play_struct, play_struct_pointer); + + print_string(play_struct.a_string); + + char* string2 = "Test"; + change_string(play_struct.a_string, &string2); + print_string(string2); + return 0; +} \ No newline at end of file