What is the difference between Person and Account?

struct Account {
    address addr ;
    uint balance ;

Account[ ] public accounts;

function applyInterest () public returns ( uint ) {
    for ( uint i = 0; i < accounts . length ; i++) {
        // apply 5 percent interest
        accounts [i]. balance = accounts [i]. balance * 105 / 100;

& Person is:

Person[] public people;

uint256 public peopleCount;

struct Person {
    string _firstName;
    string _lastName;

function addPerson(string memory _firstName, string memory _lastName) public {
    people.push(Person(_firstName, _lastName));
    peopleCount += 1;

If I use: People[0] .push(…..), I am getting syntax error on Remix IDE.

Somebody please guide me.


1 Answer 1


First of all, you are using People, while the name of your variable is people.

Second, you can call push on an array, but you are trying to call it on an array element.

In short, replace this:


With this:

  • Why is people[0].push giving syntax error? On the other hand, I can use accounts[i].balance? what is the difference between Account[ ] & Person[ ]? Why I can't use '[ ]' brackets with people?
    – zak100
    Commented Jan 19, 2020 at 14:09
  • 1
    @zak100: Did you bother to read the answer? It refers to each one of these question!!! The push keyword is a built-in method in Solidity, which you can call on an array, not on an array element. It has no correlation whatsoever with .balance, which in your case is a reference to a field in the Account structure, so there is absolutely no room for comparison here. Commented Jan 19, 2020 at 14:11
  • Thanks for your information about push. I verified by appending a balance field in the struct .
    – zak100
    Commented Jan 19, 2020 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.