c - How to change values of a struct passed to a function -
Hello friends I am practicing the structures I have these two functions which gives back the structure and I I copy into local structure. My second function changes those local structure members by entering various entities. Now I have printed the result after calling each function, for my surprise, I think the results printed after both functions are the same. I am unable to understand what is happening here? | Can you tell me please explain to me ?? Thanks!
#include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; Structure Student {Core Name [30]; Float marks; }; Structure student read_student (); Zero read_student_p (STREET student student 3); Zero print_student (student student 2 structure); Int main () {struct student student1; Student1 = read_student (); Print_student (student1); Read_student_p (student1); Print_student (student1); System ("pause"); Return 0; } // This is my first function structure student read_student () {struct student student2; Printf ("Enter the student name for the first function: \ n"); Scanf ("% s", & amp; student2.name); Printf ("Enter student number for first function: \ n"); Scanf ("% f", & amp; student2.marks); Return student 2; } // void print_student (struct student my_student) The job to print {printf ("The first function is the student's name:% s \ n", my_student.name); Printf ("The first function has student numbers:% f \ n", my_student.marks); }; // My second job is zero read_student_p (stunt student student 3) {printf ("Enter student name for second function: \ n"); Scanf ("% s", & amp; student3.name); Printf ("Enter student number for second function: \ n"); Scanf ("% f", & amp; student3.marks); }
Do you want to type
zero Read_student_p (Structured Student * Student 3) ^ {read_student_p (& student1); ^ You have to pass an indicator on read_student_p if you want to change struct , which you are passing. At present, it is passed by value, and modifications are lost. Keeping in mind the prefix _p , I hope that this objective was ..
Comments
Post a Comment