Sebelum memulai pemrograman C/C++ terlebih dahulu install compiler C/C++
1 | sudo apt-get install build-essential |
Setelah proses install selesai compiler siap dites.
Bahasa C
Buat source code C dengan nama file first.c
1 2 3 4 5 6 | #include int main() { printf("hello, worldn"); return 0; } |
Compile source codenya
1 | cc -c first.c |
Buat outputnya
1 | cc -o first first.c |
Eksekusi file outputnya
1 | ./first |
Hasil eksekusi yang akan ditampilkan
1 | Hello, world |
Bahasa C++
Buat source code C++ first.cpp
1 2 3 4 5 6 | #include int main() { std::cout << "hello world!" << std::endl; return 0; } |
Buat file output
1 | g++ first.cpp -o test |
Eksekusi file output
1 | ./test |
Hasilnya
1 | Hello World! |
via ubuntugeek.com