C for Rust Developers
Move from Rust to C17: explicit interfaces, pointers, arrays, strings, ownership and structs. Build a multi-file stock ledger and port two complete programs.
Rust and C side by side
The same program in Rust and in C, from the lessons of this course.
Printing and Comments
Rust formatting checks trait compatibility at compile time. C printf trusts a variadic format string and cannot provide the same guarantee; mismatched conversions can cause undefined behavior.
Rust1 2fn main(){3println!("value={}",7);4}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
Rust conditions require bool. C accepts scalar conditions, so a non-null pointer to an empty byte string is true; pointer presence and string emptiness are different questions.
Rust1 2fn main(){3let s="";println!("{}",s.is_empty());4}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
Rust array types retain length and slices carry a runtime length with a borrow. C pointer parameters carry neither a length nor a checked lifetime; pass size separately and maintain the relationship manually.
Rust1 2fn main(){3let a=[2,4,6];println!("{}",a.len());4}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
Rust Copy integers pass by value, while non-Copy values may move into a function. C always copies argument values and has no move checking; copying an owning pointer does not invalidate its old name.
Rust1fn change(mut x:i32){x=9;let _=x;}2fn main(){3let x=2;change(x);println!("{}",x);4}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
Rust &mut expresses an exclusive, checked borrow with a lifetime. A C int* can update the same shape of data but carries no exclusivity or lifetime proof. Non-null does not mean live or valid.
Rust1 2fn main(){3let mut n=2;{let p=&mut n;*p=5;}println!("{}",n);4}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
Rust parse returns Result and rejects malformed complete integer text. C prefix parsers can succeed before trailing bytes; full-input validity must be checked explicitly rather than inferred from one assigned value.
Rust1 2fn main(){3println!("{}","12x".parse::<i32>().is_ok());4}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 Rust Developers for?
For people who already write Rust and want to learn C. Each lesson starts from Rust 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 Rust basics: variables, conditions, loops, functions and collections.
How many lessons does C for Rust Developers have?
C for Rust Developers contains 48 interactive lessons you can complete at your own pace.
What does C for Rust 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 Rust Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.