rogerfederer07's blog

By rogerfederer07, history, 3 years ago, In English
int a[100];
int sum = 0;
for(int i = 0; i < 100; ++i) {
    cin >> a[i];
    sum += a[i];
}

and

int sum = 0;
for(int i = 0; i < 100; ++i) {
    int val;
    cin >> val;
    sum += val;
}

My doubt is whether both the code snippets consume same amount of memory ?

Thanks in advance!

Edit : I don't understand why it's getting downvoted despite being a valid doubt.

  • Vote: I like it
  • -3
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Of course not.

You use an array in the first code so it'll consume more memory than the second one.