Can you give me examples of expression where expression results into value?
Can you give me examples of expression where expression results into value?
Not sure I understand your question at all. An expression in C can be one of many things. There is no requirement that the result is constant.
Even boolean expressions result in numerical results. Something like (0 != 0) will actually result in 0.
I believe what you mean is that the output of the expression is always consistent. Constant means a value cannot be changed. Either way, it's all semantics, and I think I might understand the question now.
For the built-in boolean operators, I believe the output is always guarenteed to be 0 or 1. Nevertheless, such as assumption that you only have to worry about 1 and 0 could bite you later on.
There are functions defined in C that return various non-zero values depending upon other factors. For instance, strcmp() is guarenteed to return 0 if the strings are equal and a non-zero value if the strings in question are not equal. In particular, I believe it is defined to return a negative number if the first string is less than the second, and a positive non-zero number if the reverse condition is true.
If this doesn't answer your question, you need to be more specific.
The result of an operation on any non-constant variable. For example:The result is a non-constant value. Try initializing const arrays with the results of function calls, or addresses of pointers. Your compiler should tell you it doesn't result in a constant.Code:int a, b,c; ... c = a + b;
Or again, explain further what it is you're talking about.
Quzah.
Hope is the first step on the road to disappointment.
The output of the expression is always numeric or decimal value? Is there any case where value is different?
Ok, I'll take the risk you might not understand one word of what I'm saying, but I'll post it anyway. An "expression" in programming is related to the Formal Grammar of a programming language, or, more specifically the production:
expression -> ...
where "..." depends from one language to another. I'll post an easy example of a formal grammar from a language called "Drei", used at my university in the compilation course:
As you can see, if you evaluate the productions from expression that you will arrive at the production "factor". Actually, an expression can have ALL the values defined in factor (in this language). It can even take the result from a function, so you could write:Code:Expression = [ SumExpression CompOp ] SumExpression CompOp = "==" | "!=" | "<" | ">" | "<=" | ">=" SumExpression = Term | SumExpression SumOp Term SumOp = "+" | "-" | "||" Term = [ Term ProdOp ] [ NegateOp ] Factor NegateOp = "-" | "!" ProdOp = "*" | "/" | "%" | "&&" Factor = ident | number | string | "true" | "false" | "this" | "readInt" | "readChar" | "(" Expression ")" | "{" Statements "return" Expression "}" | "new" ident Arguments | Factor "." ident | Factor "." ident Arguments Arguments = "(" Expressions ")"
Here, we use a char as the expression in the if clause. Now, a char has an integere representation so you could argue that it's a numeric nevertheless.Code:char myFunc(); int main ( void ) { if (myFunc()); }
Do you see now that your question doesn't make any sense ?
fun() If this function returns void, can it be the example of the expression which does not return any value?
No, because that's not an expression, it's a statement. Just like ; by itself. It's not an expression, it's just a statement.
Quzah.
Hope is the first step on the road to disappointment.
Somewhat offtopic, I wrote a certain post where I discussed the return value of functions on an x86 system. Declaring main() as void did not stop the calling environment from reading off a return value.
fun() is a postfix expression as per my understanding
The argument would be that functions that return void are not true functions in the mathematical sense because they do not return a value. This is why some languages, particularly like BASIC, that distinguish between a subroutine, which does not return a value, and a function, which does return a value.
All you are doing when you call a function that returns void is change execution of the program to a different location, which eventually returns control back to where you were prior to the jump. Hence, I'm not sure if you could argue that void functions really form a mathematical expression.