0

I'm trying to run this code from C++ Primer plus

#include <iostream>
using namespace std;

int main() {
    int i = 20, j= 2*i;
    cout << "i = " << i << endl;
    int cats = 17,240;  //No, I don't want the number 17240
    return 0;
}

Why I'm seeing this error expected unqualified-id before numeric constant int cats = 17,240; , I don't know, I need a short explanation. Thanks

1 Answers1

2

int cats = 17,240; would be viewed by the compiler as int (cats = 17),240; due to operator precedence. And int 240; makes no sense, so a compiler diagnostic is issued.

Did you want 17240 cats? If so then drop the comma.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
  • Please see the link to book. I'm just trying to run exactly the lines written in the book under heading "Comma operator Tidbits" (link is in the question). –  Feb 21 '17 at 13:59
  • 1
    @DeepChandra: Don't include links like that in questions. They can be brittle and your particular one is not valid in certain jurisdictions. – Bathsheba Feb 21 '17 at 14:00