Use a text editor like notepad to enter these lines of code. Save the file with the name main.c.
#include <stdio.h>
int main (void) {
printf("Hello World, C program\n");}
Standard input/output library stdio contains commands that can work with common input and output devices such as keyboards and displays.
The main function is like an algebraic function in mathematics, our computer allocates space for an integer int as the answer to this function. It will be the program counter. No values are needed to compute the answer so we see void as input.
Printf is a formatted print command. Code for printf is part of stdio. Our program will print a text string Hello World, C program and exit. \n tells the computer to move to a new line.
LinuxGo to the folder where you saved the main.c file. Open a CLI command line interpreter terminal, the black box window. Type ctrl+alt+t as a shortcut.
Type which gcc then type $PATH. The which command shows gcc in directory /usr/bin/gcc. $PATH shows us where Linux will look for commands.
Type gcc main.c and a new file a.out will appear in the folder next to main.c.
gcc main.c
Type ./a.out and Linux will execute the file as a compiled binary executable.
./a.out
This is what the program is meant to do.
You have to execute a.out from the folder where it is located. The command is not visible outside of this folder, it is not in the $PATH environment like gcc.
WindowsNormally, a C compiler program like GCC is not provided as a standard part of the Windows operating system. We will have to add a compiler.
Comments