Statements and expressions are two different things. An expression has a 
value, with a type like "int", that can be returned. So it is fine to 
return the expression "*s", because it has a value.

A statement doesn't have a value, so it can't be returned. The ++ and -- 
operators are statements in Go, as the FAQ you cited explains. This is 
different from other languages, such as C.

Statements can't be used where an expression is needed.  The return 
statement needs one or more expressions as its 
arguments. https://golang.org/ref/spec#Return_statements

On Friday, July 29, 2016 at 9:32:03 PM UTC-5, CH S Phani wrote:
>
> Hello All,
>
> The below statement does not compile in Go language. The compilation error 
> is "syntax error: unexpected ++ at end of statement"
>
> return *s++
>
> The function containing this statement is as below
>
> func Incr(s *int) int {
> return *s++ //the purpose is to increment the parameter passed by 1. 
> }
>
> If I split the problematic statement as below I get the result I want.  
>
> *s++
> return *s
>
> I read some material in which it is stated that ++ and -- are statements 
> not expressions (Please refer the question " Why are ++ and -- are 
> statements and not expressions ? " in URL "
> https://golang.org/doc/faq#inc_dec";). Can somebody help in understanding 
> this..?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to