-O0: do not do any optimization, which is the default compiler options.
-O1: optimization will consume much less compile time, it is the main branch of the code, constants, and expressions were optimized.
-O2:'ll try more instruction-level optimization and optimization of register stages, it will take up more memory and compilation time during compilation.
-O3: O2 be based on more optimization, for example using a pseudo-register network, ordinary inline functions, and optimized for more cycles.
gcc -g and -ggdb are made to generate debugging information, but they are also different.
-g option using the operating system's "native format (native format)" to generate debugging information. GDB can use this information directly, other debuggers can also use this debug information.
-ggdb the GCC to generate dedicated richer debugging information GDB.