/c-cpp

Learning programming concepts in C and C++

Primary LanguageC++

Programming in C and C++

Deploy gh-pages status

Follow the tutorial here - https://pranabdas.github.io/c-cpp/

Quick start

Compile:

gcc filename.c

# linking math lib
gcc filename.c -lm

# show all compiler warnings
gcc -Wall filename.c

g++ filename.cpp

# specify certain standard
g++ -std=c++17 filename.cpp

This would produce executable with default name a.out. You can specify the executable name by using the -o flag:

gcc filename.c -o program_name

For complex programs, you can use -g (or -g3) flag to embed debugging information. -O flag can be used to optimize the executable file (-O2, -O3 denotes various levels of optimization).

Compiler (GCC/Clang) flags for warnings: -Wall, -Wextra, -Wpedantic, -Wunused.

Tools

Cppcheck

apt install cppcheck
cppcheck --enable=all filename.cpp

Misc

Cleanup (delete) all a.out from the src directory:

find /workspaces/c-cpp/src -type f -name a.out -delete

Resources