Ask Question

Write a program that defines a type for a structure that stores information on a student in ENG EK 125. Declare two variables to be this structure type, and call a function to initialize both of the structure variables, using call-by-reference.

+1
Answers (1)
  1. 17 July, 18:30
    0
    Following are the program in the C Programming Language.

    #include / /header file

    #include / /header file

    struct student//creating structure

    {

    //set integer variables

    int marks;

    int roll;

    };

    //define function

    void initial (struct student * stu)

    {

    //set integer type variables

    int marks=420;

    int roll_no=45, i;

    stu->marks=marks; //assigning the values

    stu->roll=roll_no; //assigning the values

    }

    //define main method to call the function

    int main ()

    {

    struct student stu;

    initial (&stu); //calling the function

    printf ("Total marks : %d/n", stu. marks); / /print output

    printf ("Roll No. : %d/n", stu. roll); / /print output

    return 0;

    }

    Output:

    Total marks : 420

    Roll No. : 45

    Explanation:

    Here, we define the structure "student" with a struct keyword for creating a structure.

    inside the structure, we set two integer type variable "marks", "roll".

    Then, we define a function "initial () " and pass an argument in the parameter of the function.

    inside the function, we set two integer type variable "marks", "roll_no" and assign the value in the variable "marks" to 420 and variable "roll_no" to 45. Assign the value in the structure's integer variables from the function's variable.

    Finally, we set the main method inside it we call the function "initial () " and pass the value and then, we print the output with message.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program that defines a type for a structure that stores information on a student in ENG EK 125. Declare two variables to be this ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers