Mapping structure before copying values

0 votes

Below is the code

```

pragma solidity ^0.4.18;

contract Courses {
    
    struct Instructor {
        uint age;
        string fName;
        string lName;
    }
    
    mapping (address => Instructor) instructors;     /// LINE 1
    address[] public instructorAccts;
    
    function setInstructor(address _address, uint _age, string _fName, string _lName) public {
        Instructor storage instructor = instructors[_address];   /// LINE 2
        
        instructor.age = _age;          /// LINE 3
        instructor.fName = _fName;          /// LINE 4
        instructor.lName = _lName;         /// LINE 5
        
        instructorAccts.push(_address) -1;
    }
    
    function getInstructors() view public returns(address[]) {
        return instructorAccts;
    }
    
    function getInstructor(address _address) view public returns (uint, string, string) {
        return (instructors[_address].age, instructors[_address].fName, instructors[_address].lName);
    }
    
    function countInstructors() view public returns (uint) {
        return instructorAccts.length;
    }
    
}

```

I know that in mapping , key value is used to fetch data value. So can anyone explain how LINE 2 helps copying value into `_address`. Like it is var instructor = instructors[_address]; , so it means the structure stored at value _address will be copied in struct instructor of LHS. In line 3,4,5 we are copying values in struct instructor so how those values will be copied at address _address in instructors[_address] ?

Aug 22, 2022 in Blockchain by Brijesh
• 120 points

edited Mar 4 14 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP