Go for C Developers
Transfer your C experience to Go: typed values, control flow, slices, functions, methods, interfaces and error handling. Build a tested multi-file order pipeline.
C and Go side by side
The same program in C and in Go, from the lessons of this course.
Files and the first run
C headers declare interfaces and source files are compiled and linked. Go sibling files in one directory share a package; they are not included textually. Each file declares its own imports. This runner compiles a flat package main with exactly one main…
C1#include <stdio.h>2int main(void) { puts("ready"); return 0; }Go1package main2import ("fmt")3 4func main(){fmt.Println("Go", 3)}If and scoped names
C has the conditional operator ?:; Go does not. Assign a result inside if/else or return from each branch. C switch usually falls through unless terminated; Go cases do not fall through by default. Preserve the business condition rather than carrying over…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdarg.h>5int main(void) {6 int score = 8;7 const char *label = score >= 10 ? "high" : score >= 5 ? "mid" : "low";8 puts(label);9 return 0;10}Go1package main2import ("fmt")3 4func main(){if n := len("go"); n > 1 { fmt.Println("long") } else { fmt.Println("short") }}Arrays are values
C array expressions commonly decay to pointers, losing length information at function boundaries. A Go array includes its length in its type and copies on assignment. A Go slice carries a view of backing storage; passing it copies the slice descriptor, not…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdarg.h>5int main(void) {6 int values[] = {4, 8, 12};7 printf("%d\n", values[2]);8 return 0;9}Go1package main2import ("fmt")3 4func main(){a:=[2]int{3,5}5b:=a6b[0]=97fmt.Println(a[0],b[0])}Typed function contracts
C functions declare result and parameter types; Go places the result type after the parameter list. Both pass arguments by value. Passing a pointer value permits mutation of the pointed-to object, but rebinding the local pointer does not replace the caller…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdarg.h>5int twice(int value) { value *= 2; return value; }6int main(void) {7 int x = 3; int y = twice(x);8 printf("%d %d\n", x, y);9 return 0;10}Go1package main2import ("fmt")3func IsEven(n int) bool { return n%2==0 }4func main(){fmt.Println(IsEven(6))}Struct values
C models data with structs and functions rather than a built-in class system. Go structs likewise hold fields, but methods can be declared with receivers. There is no class inheritance or automatic constructor invocation. A factory function can establish…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdarg.h>5struct Parcel { int weight; };6int main(void) {7 struct Parcel *a = malloc(sizeof *a);8 if (a == NULL) return 1;9 a->weight = 2; struct Parcel *b = a; b->weight = 5;10 printf("%d\n", a->weight);11 free(a);12 return 0;13}Go1package main2import ("fmt")3type Label struct { Text string }4func main(){a:=Label{Text:"old"}5b:=a6b.Text="new"7fmt.Println(a.Text,b.Text)}Errors are returned values
C usually reports failures through status codes, output parameters or errno. Go ordinary errors are returned values, commonly alongside a result. Check err before using the result. Panic is not the routine replacement for a failed conversion or a rejected…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdarg.h>5int nonnegative(int value, int *out) { if (value < 0) return 0; *out = value; return 1; }6int main(void) {7 int result = 0;8 int ok = nonnegative(-2, &result);9 printf("%d %d\n", ok, result);10 return 0;11}Go1package main2import ("fmt";"errors")3func Positive(n int)(int,error) { if n<=0{return 0,errors.New("not positive")};return n,nil }4func main(){_,e:=Positive(-2)5fmt.Println(e!=nil)}
Syllabus
9 chapters48 lessons1 project48 challenges99 quiz questionsValues and expressions
7 lessonsControl flow
5 lessonsCollections
6 lessonsFunctions and pointers
6 lessonsTypes and behavior
8 lessonsErrors and organization
6 lessonsText and absence
4 lessonsOrder pipeline
Project4 lessonsFinal challenges
2 lessonsFrequently asked questions
Who is Go for C Developers for?
For people who already write C and want to learn Go. Each lesson starts from C you know and shows how Go does the same thing, so you skip the beginner basics.
Do I need to know Go already?
No. The course starts with your first Go program. You need C basics: variables, conditions, loops, functions and collections.
How many lessons does Go for C Developers have?
Go for C Developers contains 48 interactive lessons you can complete at your own pace.
What does Go for C Developers cover?
The course is organized into chapters covering: Values and expressions, Control flow, Collections, Functions and pointers, and more.
Is Go for C Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.