Place Your Query
-
C Programming
-
- Control flow-based C Programs
- Enjoy Conditional Programming in C using If...else and switch statement.
- Good, Now write a C program to display "Hello World" on the screen.
- Write a C program to display Your Name, Address and City in different lines.
- C program to find sum of n numbers
- Write a C program For Addition of two numbers using Function.
- Write a Program to Find Simple Interest and Compound Interest.
- Write a Program to Convert Celsius To Fahrenheit and Vice Versa.
- Write a Program to Find Area and Perimeter of Circle, Triangle, Rectangle and Square.
- Write a Program to Swap Two Numbers Using Temporary Variables and Without Using Temporary Variables
- Write a C Program to Design a Simple Menu Driven Calculator
- Simple Expression Based C Programs
-
- 7. Components of C language
- 1. Introduction to C Programming Language
- 10. Operator Precedence and Associativity
- 11. Comments in C Programming
- 14. Fundamental Control Structure Statements in C [Part-1]
- 15. Fundamental Control Structure Statements in C [Part-2]
- 16. Looping Statements [Fundamental Control Structure Statements in C. #Part-3]
- 17. Keyword break, continue, return and exit [Fundamental Control Structure Statements in C. #Part-4]
- 2. Computer Languages
- 3. Interpreters vs Compilers vs Assemblers in programming languages
- 4. C Program Structure
- 5. Compile and Execute C Program
- 6. Errors in C Program
- 8. C Datatypes
- 9. Operators in C
- Control flow-based C Programs
- Demystifying Bit Masking: Unlocking the Power of Bitwise Operators in C-Language with best Examples.
- 18. Fundamentals of C Functions
- Show Remaining Articles (3)Collapse Articles
-
-
Java
-
AI ML
-
FAQs
- A Program to find Tokens in C code?
- What are the Common Coding Mistakes.
- Easy Learning, Python QAs for Beginner’s to Pro Part-1
- Easy Learning, Python QAs for Beginner’s to Pro Part-2
- Easy Learning, Python Strings QAs for Beginner’s to Pro Part-1
- Easy Learning, Python Strings QAs for Beginner’s to Pro Part-2
- Easy Learning, Python String Functions QAs for Beginner to Pro Part-3
-
Python Interview Questions
- Easy Learning, Python QAs for Beginner’s to Pro Part-1
- Easy Learning, Python QAs for Beginner’s to Pro Part-2
- Easy Learning, Python Strings QAs for Beginner’s to Pro Part-1
- Easy Learning, Python Strings QAs for Beginner’s to Pro Part-2
- Easy Learning, Python String Functions QAs for Beginner to Pro Part-3
5. Compile and Execute C Program
C is a powerful and widely used programming language that can run on different platforms. To compile and execute a C program, you need a C compiler and an editor. A compiler is a software that converts the source code written in C into an executable file that can be run by the computer. An editor is a software that allows you to write and edit the source code. There are many compilers and editors available for C, such as GCC, Visual Studio, Dev C++, CodeBlocks, etc.
Quick Links
Compile C Program
Source File
This file contains the source code of the program. The file extension of any c file is .c. The file contains C source code that defines the main function & maybe other functions.
Header File
A header file is a file with extension .h which contains the C function declarations and macro definitions and to be shared between several source files.
Assembly File
Assembly code is made by the compiler with an extension *.s, this is further being used to create a *.obj or *.o object file.
Object File
An object file is a file containing object code, with an extension .obj or .o, meaning relocatable format machine code that is usually not directly executable. Object files are produced by an assembler, compiler, or other language translator, and used as input to the linker, which in turn typically generates an executable or library by combining parts of object files.
Executable File
The binary executable file is generated by the linker. The linker links the various object files to produce a binary file that can be directly executed.
Compilation and Execution steps
Source code is the C program that you write in your editor and save with a ‘ .C ‘ extension. Which is un-compiled (when written for the first time or whenever a change is made in it and saved).
Object code is the output of a compiler after it processes the source code. The object code is usually a machine code, also called a machine language, which can be understood directly by a specific type of CPU (central processing unit), such as x86 (i.e., Intel-compatible) or PowerPC. However, some compilers are designed to convert source code into an assembly language or some other another programming language.
An assembly language is a human-readable notation using the mnemonics (mnemonics a symbolic name for a single executable machine language instruction called an opcode) in the ISA (Instruction Set Architecture) of that particular CPU.
Executable (also called the Binary) is the output of a linker after it processes the object code. A machine code file can be immediately executable (i.e., runnable as a program), or it might require linking with other object code files (e.g. libraries) to produce a complete executable program.
Compile and Execute the C Program (in Dev C++ IDE)
Let us see how to save the source code in a file, and how to compile and run it using the IDE Dev-C++. Following are the simple steps −
#include // header file for input/output functions
int main()
{
printf("\n Hello, Bharat!"); // print the message using the printf function
return 0; /* return 0 to indicate successful execution */
}
- Open a text editor and add the above-mentioned code.
- Save the file as hello.c
- Go to execute menu then select compile (F9) option.
- Once there is no error in program, go to execute menu then select Execute (F10) option.
- On output window of DevC++ you will find the output as “hello Bharat”.
Recommended Readings
- C Program Structure
- Control Flow-based C Programs
- Errors in C Programs
Congratulations! You have successfully compiled and executed a C program!