How To Compile And Run a C/C++ Code In Linux

You can compile and run a C/C++ code in Linux using the following steps:

  1. Open a terminal window.
  2. Create a file for your C/C++ code and save it with a .c or .cpp extension, e.g. code.c or code.cpp.
  3. Compile the code using the GCC compiler by running the following command:
gcc code.c -o code

or

g++ code.cpp -o code

Note: The -o option is used to specify the output file name. The default output file name is a.out if the -o option is not specified.

  1. Run the compiled code by typing:
./code
  1. The output of the code will be displayed on the terminal.

Note: If the code contains any errors, they will be reported by the GCC compiler during the compilation step. You will need to fix the errors and recompile the code before you can run it.

Leave a Comment