C for TypeScript Developers
Move from TypeScript to C17: explicit interfaces, pointers, arrays, strings, ownership and structs. Build a multi-file stock ledger and port two complete programs.
TypeScript and C side by side
The same program in TypeScript and in C, from the lessons of this course.
Printing and Comments
TypeScript console.log converts any value to text at run time and ends the line for you, and a template literal inserts values with ${...}. C printf takes variadic arguments described by conversion specifiers in its format string. Nothing converts them for…
TypeScript1// A template literal builds the text.2const value: number = 7;3console.log(`value=${value}`);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
TypeScript conditions use JavaScript truthiness: 0, NaN, "", null and undefined are falsy, so an empty string tests false. C accepts scalar truth tests, but a C string is reached through a pointer, and a non-null pointer to an empty string is true; testing…
TypeScript1const s: string = "";2console.log(s ? "true" : "false");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
TypeScript arrays are objects passed by reference, and any function that receives one can read its length. A C pointer parameter carries no array extent; pass length explicitly, and use sizeof for element counts only while the actual array type is visible.
TypeScript1const a: number[] = [2, 4, 6];2console.log(a.length);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
TypeScript passes every argument by value. For a number the value is the number itself; for an object it is a reference, so a function can change the object's properties but cannot make the caller's variable point somewhere else. TypeScript has no ref or out…
TypeScript1function change(x: number): void {2 x = 9;3}4 5let x = 2;6change(x);7console.log(x);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
TypeScript has no addresses: you cannot take a reference to a local variable. Objects are always reached through references the runtime manages, and the garbage collector keeps an object alive while anything can still reach it, so to let a function update a…
TypeScript1function set(box: { n: number }): void {2 box.n = 5;3}4 5const box = { n: 2 };6set(box);7console.log(box.n);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
TypeScript number parsing reports failure inside the value: parseInt reads the longest numeric prefix and ignores the rest, while Number rejects the whole text by returning NaN. NaN is still of type number, so the compiler cannot tell you a check is missing.…
TypeScript1const text = "12x";2console.log(parseInt(text, 10), Number(text));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 n=0,used=0;11int fields=sscanf(s,"%d%n",&n,&used);12printf("%d %d %d\n",fields,n,s[used]==0);13return 0;14}
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 TypeScript Developers for?
For people who already write TypeScript and want to learn C. Each lesson starts from TypeScript 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 TypeScript basics: variables, conditions, loops, functions and collections.
How many lessons does C for TypeScript Developers have?
C for TypeScript Developers contains 48 interactive lessons you can complete at your own pace.
What does C for TypeScript 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 TypeScript Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.