Home > database >  How is printf() an expression?
How is printf() an expression?

Time:12-29

I was trying to learn value categories because of an error that I got and stared watching screenshot with printf

How is printf() an expression? I always thought that function calls aren't really an expression when written by themselves. They are more like statements as my beginner mind thinks of it. Moreover, the definition they provide mentions operators and operands but none can be seen with printf. What am I missing?

The data type that is mentioned is the return value for printf. What about functions that return void?

CodePudding user response:

How is printf() an expression?

It's a function call expression.

I always that that function calls aren't really an expression

Function calls are expressions.

They are more like statements

Function calls are not statements. Consider for example ret = printf();. Here, the function call is a subexpression of the assignment expression. Statements cannot be sub expressions - expressions can be sub expressions.

Moreover, the definition they provide mentions operators and operands but none can be seen with printf.

The parentheses are the function call operator. The operands are the function (which is a postfix expression) on the left side of the parentheses and the argument list within the parentheses.

How is the expression characterized by a data type?

Every expression has a type. The type - along with the value category - affects how you can use the expression.

I thought that the data type was related to the return type of the printf function

You thought right. The type of a function call expression is determined by the return type of the function. The type of printf() is int.

  • Related