Compile and run C programming on your OS
Compile and run C programming on your OS
There are numerous compilers and
text editors you can use to run C programming. These compilers and text
editors may differ from system to system.
You will find the easiest way to run C programming on your computer (Windows, Mac OS X or Linux) in this section.
You will find the easiest way to run C programming on your computer (Windows, Mac OS X or Linux) in this section.
Run C program Online
Run C Programming in Mac OS X
Run C programming on Linux
Run C Programming in Windows (XP, 7, 8 and 10)
To run C Programming in Windows, download a software called
Code::Blocks. Then, write C code, save the file with .c extension and
execute the code.
To make this procedure even easier, follow this step by step guide.
To make this procedure even easier, follow this step by step guide.
- Go to the binary release download page of Code:Blocks official site.
- Under Windows XP / Vista / 7 / 8.x / 10 section, click the link with mingw-setup (highlighted row) either from Sourceforge.net or FossHub.
- Open the Code::Blocks Setup file and follow the instructions (Next > I agree > Next > Install); you don’t need to change anything. This installs the Code::Blocks with gnu gcc compiler, which is the best compiler to start with for beginners.
- Now, open Code::Blocks and go to File > New > Empty file (Shortcut: Ctrl + Shift + N)
- Write the C code and save the file with .c extension. To save the file, go to File > Save (Shortcut: Ctrl + S).
Important: The filename should end with a .c extension, like: hello.c, your-program-name.c
- To run the program, go to Build > Build and Run (Shortcut: F9). This will build the executable file and run it.
The fun begins: Your first C program
You will learn to write a “Hello, World!” program in this section.
This program is often used to introduce programming language to a beginner. So, let’s get started.
C programming is small and cannot do much by itself. You need to use libraries that are necessary to run the program. The
Why do you need stdio.h file in this program?
In this program, we have used
The main() function
In C programming, the code execution begins from the start of main() function (doesn’t matter if
The code inside the curly braces { } is the body of
The printf() function
The
In our program, it displays Hello, World! on the screen.
Remember, you need to include
The return statement
The return statement
Why “Hello, World!” program?
“Hello, World!” is a simple program that displays “Hello, World!” on the screen. Since, it’s a very simple program, it is used to illustrate the basic syntax of any programming language.This program is often used to introduce programming language to a beginner. So, let’s get started.
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
How “Hello, World!” program works?
Include stdio.h header file in your program.C programming is small and cannot do much by itself. You need to use libraries that are necessary to run the program. The
stdio.h
is a header file and C compiler knows the location of that file. To use the file, you need to include it in your program using #include
preprocessor.Why do you need stdio.h file in this program?
In this program, we have used
printf()
function which displays the text inside the quotation mark. Since printf()
is defined in stdio.h
, you need to include stdio.h
.The main() function
In C programming, the code execution begins from the start of main() function (doesn’t matter if
main()
isn’t located at the beginning).The code inside the curly braces { } is the body of
main()
function. The main()
function is mandatory in every C program.int main() { }This program doesn’t do anything but, it’s a valid C program.
The printf() function
The
printf()
is a library function that sends formatted
output to the screen (displays the string inside the quotation mark).
Notice the semicolon at the end of the statement.In our program, it displays Hello, World! on the screen.
Remember, you need to include
stdio.h
file in your program for this to work.The return statement
The return statement
return 0;
inside the main()
function ends the program. This statement isn’t mandatory. However, it’s considered good programming practice to use it.Key notes to take away
- All C program starts from the
main()
function and it’s mandatory. - You can use the required header file that’s necessary in the program. For example: To use
sqrt()
function to calculate square root andpow()
function to find power of a number, you need to includemath.h
header file in your program. - C is case-sensitive; the use of uppercase letter and lowercase letter have different meanings.
- The C program ends when the program encounters the return statement inside the
main()
function. However, return statement inside the main function is not mandatory. - The statement in a C program ends with a semicolon.
Teach Yourself to Code in C
Learn C from Programiz
Programiz offers dozens of tutorials and examples to help you learn C programming from scratch.The tutorials are designed for beginners who do not have any prior knowledge of C programming (or, any other programming languages). Each tutorial is written in depth with examples and detailed explanation.
Recommended Books in C Programming
If you are serious about learning programming (any programming language including C), you should get yourself a good book.Granted, reading a 600 page long programming book takes a lot of time and patience. But, you will get the big picture of programming concepts in the book which you may not find elsewhere.
Here are 3 books we personally recommend.
No comments