Q:

Is the following program legal? If so, what values are printed?

0

Is the following program legal? If so, what values are printed?

int i = 100, sum = 0;
for (int i = 0; i != 10; ++i)
sum += i;
std::cout << i << " " << sum << std::endl;

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>

int main() {
  int i = 100, sum = 0;
  for (int i = 0; i != 10; ++i)
    sum += i;
  std::cout << i << " " << sum << std::endl;  // 100 45

  return 0;
}

 

Output:

100 45

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now