Can anyone please explain me the following solidity code?
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
add a comment |
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
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
add a comment |
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
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
solidity
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Jan 27 at 8:00
goodvibrationgoodvibration
4,26411024
4,26411024
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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