如何更改传递给函数的结构的值

stu*_*ded 3 c

嗨朋友,我正在练习结构.我有这两个函数返回结构,我将它复制到main中的本地结构.我的第二个函数通过输入不同的实体来更改这些本地struct成员 现在我在调用每个函数后打印结果,令我惊讶的是我注意到两个函数之后的打印结果是一样的.我无法理解这里发生了什么......你能解释一下我...谢谢!

 #include <stdio.h>
 #include <stdlib.h>

 struct student{
        char name[30];
        float marks;
        };


 struct student read_student();
 void read_student_p(struct student student3);
 void print_student(struct student student2);

 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
 struct student read_student()
 {
      struct student student2;
      printf("enter student name for first function: \n");
      scanf("%s",&student2.name);

      printf("enter student marks for first function:\n");
      scanf("%f",&student2.marks);

      return student2;
 }

//function to print 
void print_student(struct student my_student)
{
    printf("Student name in first function is : %s\n",my_student.name);
    printf("Student marks in first function are: %f\n",my_student.marks);
};

 //My second function  
 void read_student_p(struct student student3)
 {    
      printf("enter student name for second function: \n");
      scanf("%s",&student3.name);
      printf("enter student marks for second function: \n");
      scanf("%f",&student3.marks);
 }
Run Code Online (Sandbox Code Playgroud)

Kar*_*k T 7

你的意思是写

void read_student_p(struct student* student3)
                                  ^
{    


read_student_p(&student1);
               ^
Run Code Online (Sandbox Code Playgroud)

read_student_p如果要修改要传递的内容,则需要传递指针struct.目前它按值传递,并且修改丢失.

考虑到_p后缀,我希望这是有意的..