Can anyone please explain me the following solidity code?












1















What is the use of -1 in instructorAccts.push(_address) -1?



function setInstructor(address _address, uint _age, string _fName, string _lName) public {
var instructor = instructors[_address];
instructor.age = _age;
instructor.fName = _fName;
instructor.lName = _lName;

instructorAccts.push(_address) -1;
}









share|improve this question




















  • 2





    See ethereum.stackexchange.com/questions/40312/…

    – ivicaa
    Jan 27 at 8:01











  • My guess is -1 was blindly copied from another example. push()-1 corresponds to the row in the array occupied by the appended element. As @goodvibration points out, the result of this work isn't assigned to anything (e.g. uint position = array.push(value) -1) so the extra work is pointless.

    – Rob Hitchens
    Jan 27 at 22:19
















1















What is the use of -1 in instructorAccts.push(_address) -1?



function setInstructor(address _address, uint _age, string _fName, string _lName) public {
var instructor = instructors[_address];
instructor.age = _age;
instructor.fName = _fName;
instructor.lName = _lName;

instructorAccts.push(_address) -1;
}









share|improve this question




















  • 2





    See ethereum.stackexchange.com/questions/40312/…

    – ivicaa
    Jan 27 at 8:01











  • My guess is -1 was blindly copied from another example. push()-1 corresponds to the row in the array occupied by the appended element. As @goodvibration points out, the result of this work isn't assigned to anything (e.g. uint position = array.push(value) -1) so the extra work is pointless.

    – Rob Hitchens
    Jan 27 at 22:19














1












1








1








What is the use of -1 in instructorAccts.push(_address) -1?



function setInstructor(address _address, uint _age, string _fName, string _lName) public {
var instructor = instructors[_address];
instructor.age = _age;
instructor.fName = _fName;
instructor.lName = _lName;

instructorAccts.push(_address) -1;
}









share|improve this question
















What is the use of -1 in instructorAccts.push(_address) -1?



function setInstructor(address _address, uint _age, string _fName, string _lName) public {
var instructor = instructors[_address];
instructor.age = _age;
instructor.fName = _fName;
instructor.lName = _lName;

instructorAccts.push(_address) -1;
}






solidity






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 27 at 20:58









Rosco Kalis

1,1111421




1,1111421










asked Jan 27 at 7:49









Saiteja KuruvaSaiteja Kuruva

165




165








  • 2





    See ethereum.stackexchange.com/questions/40312/…

    – ivicaa
    Jan 27 at 8:01











  • My guess is -1 was blindly copied from another example. push()-1 corresponds to the row in the array occupied by the appended element. As @goodvibration points out, the result of this work isn't assigned to anything (e.g. uint position = array.push(value) -1) so the extra work is pointless.

    – Rob Hitchens
    Jan 27 at 22:19














  • 2





    See ethereum.stackexchange.com/questions/40312/…

    – ivicaa
    Jan 27 at 8:01











  • My guess is -1 was blindly copied from another example. push()-1 corresponds to the row in the array occupied by the appended element. As @goodvibration points out, the result of this work isn't assigned to anything (e.g. uint position = array.push(value) -1) so the extra work is pointless.

    – Rob Hitchens
    Jan 27 at 22:19








2




2





See ethereum.stackexchange.com/questions/40312/…

– ivicaa
Jan 27 at 8:01





See ethereum.stackexchange.com/questions/40312/…

– ivicaa
Jan 27 at 8:01













My guess is -1 was blindly copied from another example. push()-1 corresponds to the row in the array occupied by the appended element. As @goodvibration points out, the result of this work isn't assigned to anything (e.g. uint position = array.push(value) -1) so the extra work is pointless.

– Rob Hitchens
Jan 27 at 22:19





My guess is -1 was blindly copied from another example. push()-1 corresponds to the row in the array occupied by the appended element. As @goodvibration points out, the result of this work isn't assigned to anything (e.g. uint position = array.push(value) -1) so the extra work is pointless.

– Rob Hitchens
Jan 27 at 22:19










1 Answer
1






active

oldest

votes


















2














The expression instructorAccts.push(_address) equals to the length of the instructorAccts array after pushing the _address item into it.



The expression instructorAccts.push(_address) - 1 equals to the length of the instructorAccts array before pushing the _address item into it.



In your example, since this value is not stored or used in any manner, this expression has no effect.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "642"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f66203%2fcan-anyone-please-explain-me-the-following-solidity-code%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    The expression instructorAccts.push(_address) equals to the length of the instructorAccts array after pushing the _address item into it.



    The expression instructorAccts.push(_address) - 1 equals to the length of the instructorAccts array before pushing the _address item into it.



    In your example, since this value is not stored or used in any manner, this expression has no effect.






    share|improve this answer




























      2














      The expression instructorAccts.push(_address) equals to the length of the instructorAccts array after pushing the _address item into it.



      The expression instructorAccts.push(_address) - 1 equals to the length of the instructorAccts array before pushing the _address item into it.



      In your example, since this value is not stored or used in any manner, this expression has no effect.






      share|improve this answer


























        2












        2








        2







        The expression instructorAccts.push(_address) equals to the length of the instructorAccts array after pushing the _address item into it.



        The expression instructorAccts.push(_address) - 1 equals to the length of the instructorAccts array before pushing the _address item into it.



        In your example, since this value is not stored or used in any manner, this expression has no effect.






        share|improve this answer













        The expression instructorAccts.push(_address) equals to the length of the instructorAccts array after pushing the _address item into it.



        The expression instructorAccts.push(_address) - 1 equals to the length of the instructorAccts array before pushing the _address item into it.



        In your example, since this value is not stored or used in any manner, this expression has no effect.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 27 at 8:00









        goodvibrationgoodvibration

        4,26411024




        4,26411024






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ethereum Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f66203%2fcan-anyone-please-explain-me-the-following-solidity-code%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules