C is a procedural programming language. It was initially developed by Dennis Ritchie between 1969 and 1973. It was mainly developed as a system programming language to write an operating system. The main features of C language include low-level access to memory, a simple set of keywords, and clean style, these features make C language suitable for system programmings like an operating system or compiler development.
First, we need to install some development tools and applications such as GNU, GCC, C/C++ compiler to compile and execute the code on Linux. You can verify the installed tools using the following command:
To check the version information of cc:
cc -v
Now consider a simple C program file named as Geeks.c as follows:
#include <stdio.h> int main(void) { printf("Hello! Geeks\n"); return 0; } |
To compile this code we can use:
cc filename.c -o executable_file_name
Here, filename.c is the C program file and -o option is used to show the errors in the code. If no error founds then this will generate an executable file as executable_file_name.
cc Geeks.c -o geeksoutput
Here, geeksoutput is the executable file which is generated. So we can execute it like:
./geeksoutput
For C++ Program Files:
C++ is a general-purpose programming language and widely used nowadays for competitive programming. It has imperative, object-oriented and generic programming features. C++ runs on lots of platform like Windows, Linux, Unix, Mac etc. Before we start programming with C++. We will need an environment to be set-up on our local computer to compile and run our C++ programs successfully. You can verify the installed tools using the following command:
To check the version information of g++:
g++ --version
Now consider a simple C++ program file named as geeks.cpp as follows:
#include<iostream> using namespace std; // main function // where the execution // of program begins int main() { // prints Hello World! cout<<"Hello World!\n"; return 0; } |
To compile this code we can use:
g++ filename.cpp -o executable_file_name
Here, filename.cpp is the C++ program file and -o option is used to show the errors in the code. If no error founds then this will generate an executable file as executable_file_name.
g++ geeks.cpp -o geeksoutput
Here, geeksoutput is the executable file which is generated. So we can execute it like:
./geeksoutput
For Java Program Files:
Java is one of the most popular and widely used programming language and platform. A platform is an environment that helps to develop and run programs written in any programming language. You can verify the installed tools using the following command:
To check the version information of Java:
javac -version
To compile the code we can use:
javac filename.java
To execute we will use the name of the class which contains the main method as follows:
java classname
Example: Now consider a simple Java program file named as HelloWorld.java as follows:
class HelloWorld { // Main Method public static void main(String args[]) { System.out.println("Hello, GFG"); } } |
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- Difference between Compile-time and Run-time Polymorphism in Java
- VS Code | Compile and Run in C++
- Run Levels in Linux
- How to run Linux Commands on Windows 10?
- Run python script from anywhere in linux
- How to compile 32-bit program on 64-bit gcc in C and C++
- Runtime and Compile-time constants in C++
- Write a C program that won't compile in C++
- Python compile() Function
- Pattern compile(String) method in Java with Examples
- Pattern compile(String,int) method in Java with Examples
- Compile our own Android Kernel in 5 Simple Steps
- Difference between Thread.start() and Thread.run() in Java
- Why is Java 'write once and run anywhere'?
- How to start nmap and run a simple scan ?
- How to Install and Run Apache Kafka on Windows?
- How to create an instance of a Metaclass that run on both Python2 and Python3?
- VS Code | Build, Run and Debug in C++
- RTTI (Run-time type Information) in C++
- How to run java class file which is in different directory?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.








