1

Good day guys, I'm a beginner of c++ and trying various approaches.

#include <iostream>

using namespace std;

int main() {
    int num = 0;
    while (num < 100) {
        cout << num << "\t" << num * num << "\n";
        num++;
    }
}

This code prints numbers and square numbers of these, as you know. And I wanted a minimalized version, so I tried it.

#include <iostream>

using namespace std;

int main() {
    int num = 0;
    while (num < 100) cout << num << "\t" << num * num++ << "\n";
}

But it prints

++n     n^2

unexpected. Why it results like this, and how to simplify it using the ++ operator properly? Thanks for reading.

noError
  • 21
  • 2

0 Answers0