C for Go Developers
Move from Go to C17: explicit interfaces, pointers, arrays, strings, ownership and structs. Build a multi-file stock ledger and port two complete programs.
Go and C side by side
The same program in Go and in C, from the lessons of this course.
Printing and Comments
Go fmt inspects typed arguments and reports formatting mismatches in output. C printf trusts the variadic format contract; a mismatched type can cause undefined behavior.
Go1package main2import ("fmt")3 4func main(){5fmt.Printf("value=%d\n",7)6}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10printf("value=%d\n",7);11return 0;12}Booleans and Branches
Go requires bool conditions. C accepts scalar truth tests, so a pointer to an empty string is true when non-null; use an explicit emptiness check rather than translating Go len semantics into a pointer test.
Go1package main2import ("fmt")3 4func main(){5s:="";fmt.Println(len(s)==0)6}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10const char *s=""; printf("%s\n",s?"true":"false");11return 0;12}Arrays Need Lengths
Go slices carry a length and capacity in their descriptor. C pointers carry neither. A C pointer/length pair resembles a borrowed view, but C does not enforce its bounds or lifetime.
Go1package main2import ("fmt")3 4func main(){5a:=[]int{2,4,6};fmt.Println(len(a))6}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10int a[]={2,4,6};printf("%zu\n",sizeof a/sizeof a[0]);11return 0;12}Function Arguments Are Values
Go passes values, including pointer and slice descriptors, by value. C likewise copies arguments. Mutating through a copied pointer affects the pointee; reassigning the local pointer does not replace the caller pointer.
Go1package main2import ("fmt")3func change(x int){x=9;_ = x}4func main(){5x:=2;change(x);fmt.Println(x)6}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8static void change(int n){n=9;(void)n;}9int main(void) {10int x=2;change(x);printf("%d\n",x);11return 0;12}Addresses and Dereferencing
Go and C both use & and * for addresses and dereferencing. Go keeps escaped objects alive through garbage collection; C can leave a pointer dangling when its automatic object leaves scope.
Go1package main2import ("fmt")3 4func main(){5n:=2;p:=&n;*p=5;fmt.Println(n)6}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10int n=2;int *p=&n;*p=5;printf("%d\n",n);11return 0;12}Parsing with Status Results
Go Atoi returns an error for malformed input. C scanf-style conversions can accept a numeric prefix; the caller must decide and enforce whether trailing bytes invalidate the whole input.
Go1package main2import ("fmt";"strconv")3 4func main(){5_,err:=strconv.Atoi("12x");fmt.Println(err==nil)6}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10const char *s="12x";int ok=*s!=0;for(size_t i=0;s[i];i++)if(s[i]<'0'||s[i]>'9')ok=0;printf("%d\n",ok);11return 0;12}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsCompile and Compute
6 lessonsDecisions and Loops
5 lessonsArrays and Text
5 lessonsFunctions and Interfaces
5 lessonsPointers and Structs
5 lessonsValidation and Text Buffers
5 lessonsOwned Dynamic Memory
5 lessonsTagged Data and Composition
6 lessonsProject: Stock Ledger
4 lessonsFinal Source Ports
2 lessonsFrequently asked questions
Who is C for Go Developers for?
For people who already write Go and want to learn C. Each lesson starts from Go you know and shows how C does the same thing, so you skip the beginner basics.
Do I need to know C already?
No. The course starts with your first C program. You need Go basics: variables, conditions, loops, functions and collections.
How many lessons does C for Go Developers have?
C for Go Developers contains 48 interactive lessons you can complete at your own pace.
What does C for Go Developers cover?
The course is organized into chapters covering: Compile and Compute, Decisions and Loops, Arrays and Text, Functions and Interfaces, and more.
Is C for Go Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.