diff options
author | Rob Pike <r@golang.org> | 2008-09-11 10:21:02 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2008-09-11 10:21:02 -0700 |
commit | 886b5d5ad8190ca7e49221fd69091e5a9bf7b914 (patch) | |
tree | 9029a8e180e733c86dfd6dd301eeaec55c70b0dc /doc/progs | |
parent | 5a95ea84656ecd0abfbb14322c647b5779282075 (diff) | |
download | go-886b5d5ad8190ca7e49221fd69091e5a9bf7b914.tar.gz |
add sections about types and constants
R=gri
DELTA=133 (124 added, 0 deleted, 9 changed)
OCL=15122
CL=15143
Diffstat (limited to 'doc/progs')
-rw-r--r-- | doc/progs/strings.go | 13 | ||||
-rw-r--r-- | doc/progs/sum.go | 19 |
2 files changed, 32 insertions, 0 deletions
diff --git a/doc/progs/strings.go b/doc/progs/strings.go new file mode 100644 index 000000000..28553c26a --- /dev/null +++ b/doc/progs/strings.go @@ -0,0 +1,13 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + s := "hello"; + if s[1] == 'e' { print("success") } + s = "good bye"; + var p *string = &s; + *p = "ciao"; +} diff --git a/doc/progs/sum.go b/doc/progs/sum.go new file mode 100644 index 000000000..c8e7b10a7 --- /dev/null +++ b/doc/progs/sum.go @@ -0,0 +1,19 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func sum(a *[]int) int { // returns an int + s := 0; + for i := 0; i < len(a); i++ { + s += a[i] + } + return s +} + + +func main() { + s := sum(&[]int{1,2,3}); // pass address of int array + print(s, "\n"); +} |