Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an example of an expression that does not produce a value?

Tags:

c++

The c++ defines the expression as

"An expression is a sequence of operators and their operands, that specifies a computation. Expression evaluation may produce a result"

https://en.cppreference.com/w/cpp/language/expressions

Are there any expressions that does not produce a result ?

like image 567
Talespin_Kit Avatar asked Sep 16 '25 07:09

Talespin_Kit


1 Answers

Sure.

Any expression that produces a result of type void. The most obvious would be evaluating a call to a function that returns void. That will (at least normally) have some side effects, but it won't produce a value as its result.

#include <iostream>

void foo() { std:cout << "foo\n"; }

int main() { 
    foo(); // evaluating this expression produces no result
}
like image 199
Jerry Coffin Avatar answered Sep 18 '25 23:09

Jerry Coffin