C Weekly | How a C program works

Hi, again I am back with a new topic. Today's topic is "How a C program works" means whenever we write a program in C language, then how it interacts with the machine, what is happening behind the scene. Before we start, let me tell you some characteristics of C language.

Characteristics of C

C is a middle-level language. It has the simplicity of a high-level language as well as the power of a low-level language. This aspect of C makes it suitable for writing both application and system programs. C is small language, consisting of only 32 English words known as keywords(if, else, for etc). The power of C is augmented by the library functions provided with it. It also allows users to add their own library functions to the library.

Structure of C programs 

A C program is a collection of one or more functions. Every function is a collection of statements and performs some tasks. The general structure of a C program is-

Compilation and Execution of C Program

Now, lets begin our topic. Whenever we write a program in any programming language, our computer does not understand our program because computer does not understand English like text it only knows two things i.e. '0' and '1'. These '0' and '1' together called Binary. The code consists of binary are known as binary codes. The language which consists binary codes is said to be Machine language or Low-level language because the machine easily understands this language.
When we write any program in C language it will translate into the machine language. there are many phases through which our program passes before being transformed into an executable form.

Preprocessor

The source code is the code that we write using any text editor and file is given an extension '.c'. This source code is firstly passed through preprocessor which expands our code and passed to the compiler.

Compiler

The expended code converted into the Machine's Assembly language code by the compiler.

Assembler

This assembly code is converted into object code by the system's assembler. The name of object file is the same as that of the source file with an extension '.obj' or in Unix '.o'.

Linker

Generally, all programs use library functions. Library functions are precompiled and their object code is stored in library files with  '.lib' or '.a' extension. The linker links the object code of library functions with the object code of our program. The output of linker is an executable file with '.exe' extension which directly runs our program.


That's all about 'How a C program works'. Let me know in the comment section if there is any question in your mind.In next Blog I'll show you how to compile C program. I'll be back with such amazing topics. Stay tuned. And please comment in the box it will motivate us. Thanks..!!

#its_Kumar

Comments

Popular posts from this blog

Conditional Statements and Conditional Operator | C Weekly

C Weekly | Data Types In C | Variables | Comments | Simple Program

Fundamentals of C | feel_the_coder | C Weekly