Javatpoint Logo
Javatpoint Logo

Go Data Types

Variables can be of different types like int, float, struct, slice or it can be of the interface.

The general form for declaring a variable uses the keyword var:

Syntax:-

Example

when a variable is declared with var it automatically initializes it to the zero-value defined for its type. A type defines the set of values and the set of operations that can take place on those values.

GO Simple Data Type Example

Output:

int float64 bool string
0   0           false  ""    

Go Construct and Data Types

The Go source code is stored in .go file. The name of the file consists of lowercase letters. If the file name has several parts, it should be separated by underscore "_" .

Go file has a name or an identifier which is case sensitive like C.

For example: a, ax123, i etc.

The _ identifier is special. It is called blank identifier. It may be used in variable declarations.

It is like normal identifiers but its value is discarded, so it cannot be used anymore in the code.

It may happen that the variable, type, or function has no name and even enhance flexibility so it is called anonymous.

These are the 25 keywords for Go-code:

break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough If range type
continue for import return var

Programs consist of keywords, constants, variables, operators, types and functions.

The following delimiters are used in constructs such as parentheses ( ), brackets [ ] and braces { }.

The following punctuation characters . , ; : and ... are used.

append bool byte cap close complex complex64 complex128 uint16
copy false float32 float64 imag int int8 int16 uint32
int32 int64 iota len make new nil panic uint64
print println real recover string true uint uint8 Uintptr

Next TopicGo Package



Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA