📄
main.c
Flags:
-Wall -O21
2
3
4
5
6
7
8
2
3
4
5
6
7
8
colab-terminal@root: /content
sh
Google Colaboratory Linux kernel initialized.
Type terminal commands:
gcc, cat main.c, ls -la, ./main
root@colab:~# gcc -Wall -O2 main.c -o main && ./main
Hello from C on Google Colab!
Variable x address: 0x7ffd5a8b, value: 42
[Process completed - return code 0]
root@colab:~#
Simulated Memory Inspection (Stack / Heap) 2 variables in scope
| Segment | Symbol / Name | Virtual Address | Value | Type |
|---|---|---|---|---|
| Stack | x |
0x7ffd5a8b |
42 |
int (4 bytes) |
| Text / Code | main() |
0x00401126 |
[Function Pointer] | entry symbol |
Reddit /r/cprogramming Origin
"i had no idea that you could run c programs on google colab, i fucked around and found out ig. so basically what i did is i entered the terminal made a directory created a main.c file edited it using vim and compiled it using gcc and voila."
Colab runs on top of standard Ubuntu container virtual machines. While primarily used for Python Jupyter notebooks, full access to the POSIX terminal, GNU Compiler Collection (GCC), Make, and Clang is standard.
GCC Compilation Architecture
When you execute gcc -Wall -O2 main.c -o main, GCC runs four distinct steps:
- Preprocessing (cpp): Expands
#include <stdio.h>and macros. - Compilation (cc1): Translates C to assembly instructions.
- Assembly (as): Converts instructions into relocatable machine ELF object code.
- Linking (ld): Binds dynamic libc functions (like
printf) into the executable binary.