Golang and C Contrast learning (1)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Control structure:

Go control structure mainly has if,switch,for three kinds, and does not have while, can use for to replace while

If

The IF condition of go is not enclosed in parentheses, but the program body part must be enclosed in curly braces to solve the ambiguity in C language.

Switch

The branch ends even if there is no break

Any value can be used in the case

Branch conditional expressions can be omitted

For

The expression is not enclosed, it is more than the C language single expression example: for condition {} is used instead of while

+ +: In the Go language, + + is not an expression but is treated as a statement.

Type declaration:

In the go language, the declaration must begin with a reserved word, and the tangent type is after the variable name

Cases:

Type T struct {x, y int}//new type const N = 1024//constant var t1 T = new (t) T2 =:new (t) var t3 *t =&t2func f (i int) float {}func F2 (i int) (Flota,int) {}

: = Simple copy, indicating that the left variable is declared as the right type at the time of assignment

Generic type:

Go does not have the concept of a template, but the built-in Array,slce,map,channel, you can specify other types,

A slice (slice) is a type that is unique to go, and can be seen roughly as a pointer to an array

The map is similar to HashMap

Channel for concurrent programming, similar to pipeline

var a[5] string//array var s[] string//String slice var m map [int] string//mapvar c chan int//pipe F: = Stacj.get. (float)//cast


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.