0

The variable and constant declarations we have seen before are also statements. As the initial value of a variable or constant, we can use any expression (except another assignment or comma operator). Other statements—to be discussed later—are function and class definitions, as well as control statements that we will introduce in the next section.

I was reading about expression, it doesn't make sense to me. what does author is trying to say ?

AFAIK, these following allowed in c++ :

int x = 2;
int y = 23;  
int z = y = x;  // as we can use another assignment expression in the initial value of an variable 
mn_op
  • 107
  • 6
  • 2
    Yes, the quote is wrong. It's also wrong to unconditionally call variable (and constant) declarations "statements", it's only the case inside of funcitions. And it's plain wrong for function and class definitions, which are never inside of functions, so are never statements. – HolyBlackCat Oct 16 '22 at 13:59
  • 2
    This is why c++ **must** be learnt using a [good c++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). Though the link provided seems to be a link to a book? I guess, that is not a good c++ book then. The books [here](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) are also available as PDFs for free. – Jason Oct 16 '22 at 14:03
  • @JasonLiam i'm using bjarne ***PPP***, but i doesn't have any explaination about expression, so i was looking on google and i found this, if you have any other reference about expression, it would be helpful. – mn_op Oct 16 '22 at 14:06
  • @HolyBlackCat i didn't find about unconditionally call variable, can you tell me where it is written in this book ? – mn_op Oct 16 '22 at 14:13
  • I just mean the first sentence. – HolyBlackCat Oct 16 '22 at 14:21

0 Answers0