Go language variables and input and output

Source: Internet
Author: User

1. Variables

1.1 Variable Declaration

The difference between Go and other languages is that the type of the variable is behind the variable name. not: int A, but a int. When a variable is defined, it is assigned a null value of its type by default. This means that after var a int, the value of a is 0. The var s string means that s is assigned a zero-length string, or "".

There are two ways to declare a variable.

The first one uses the VAR keyword to declare a variable, and then assigns a value to the variable.

Func Main () {	
	var a int;
	A = 8;
	Fmt. Println ("Value  ="  , a);
}
The second use: = Complete the Declaration and assignment of the variable at the same time.

Func Main () {	
	a:=8
	fmt. Println ("Value  ="  , a);
}

Note that the variable declaration must be used later, no compiler error.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.