我想详细了解 C++ 中表达式和语句之间的区别。请选择具体的例子来解释

I want to understand in detail distinct between expression and statement in C++. Pls pick concrete example to explain that

现在正在学习C++编程。没看懂表达式、定义、声明、定义的区别

正如维基百科所说,

In "Statement(computer science)"

In most languages, statements contrast with expressions in that statements do not return results and are executed solely for their side effects, while expressions always return a result and often do not have side effects at all.

In "Expression(Computer Science)" page

In many programming languages a function, and hence an expression containing a function, may have side effects. An expression with side effects does not normally have the property of referential transparency. In many languages (e.g. C++), expressions may be ended with a semicolon (;) to turn the expression into an expression statement. This asks the implementation to evaluate the expression for its side-effects only and to disregard the result of the expression (e.g. "x+1;") unless it is a part of an expression statement that induces side-effects (e.g. "y=x+1;" or "func1(func2());"). Caveats

具体来说,这里的“副作用”和“结果”是什么意思?

帮帮我,C++ Geeks!

声明 通知编译器给定的名称是已知的。但是,未分配对象的内存。我们不能引用一个对象,我们不能给它赋值,因为它还不存在。

extern varType varName;

定义 为给定变量保留内存space。对于哪个变量,我听到你问。没错——变量必须在某处声明,以便其名称和类型已知。好吧,这其中有一个陷阱,因为每个定义同时都是一个声明(反之则不然)。

int number;
varType varName;

表达式由按照语言规则排列的运算符、常量和变量组成。它还可以包含 return 值的函数调用。

x = a+(b*c);
bool ifTrue = a>b;

你应该阅读更多关于表达式的内容there.

Concretely, What do "side effect" and "result" mean here?

表达式没有副作用,从源代码中删除它不会改变程序语义。

int main(void) {
   int x = 1, y = 2, z = 0;
   // x+y expression calculates sum and ignores resulting answer 
   // NO SIDE EFFECTS, can be removed
   x+y; 
   // x+y expression calculates sum, but then 15 is assigned to z as a result 
   // SIDE EFFECT is that removing given expression breaks program syntax - can't be removed 
   z = (x+y, 15);
}

编辑

顺便说一句,请记住并非所有表达式 语句 也有副作用。例如 x=x; 在技术上等同于 ; - 一个空语句,它在汇编级别被编译成 NOP 或被 GCC 优化器完全跳过。所以这些类型的表达式语句没有副作用,可以安全地从程序中删除。但这并不意味着您可以在不更改程序逻辑的情况下删除 each 空语句。例如在这个片段中:
for (i=0; i < 10; i++);
此处 NOP 在每个 CPU 周期执行,因此如果您将其删除 - 程序语义将发生根本变化。