on-internet
← Community

Why does using the comma operator make the expression not considered a constant?

Stack Overflow ·

Why is the expression specified inside a comma operator (such as the example below) not considered a constant expression? For example, int a = (10,20) ; when given in global scope yields an error "initializer is not a constant", though both the expressions separated by a comma operator are constants (constant expressions). Why is the entire expression is not treated as a constant expression? For clarification I have read What does the ‘,’ operator do in C? and Uses of C comma operator. They have not dealt this aspect of comma operator.

Comments

Sign in or sign up to comment and upvote.

No comments yet.