Introduction to C Language with Example

What is the C language?

C is a high-level programming language that is used to generally built logic. C Programming language invented by Dennis Ritchie in the year 1972. It was mainly developed as a system programming language to write an operating system such as Linux, Unix, etc. All languages are based on the C language.
      The C language is a high-level language. It replaced the more familiar languages, such as FORTRAN, COBOL, BASIC, PL/I, and Pascal. Where it differs is that C permits very close interaction with the inner working of the computer. C language is popular because it is reliable, simple, and easy to use.

Structure of C:

Structure of C

The Structure of C Program:

A c program can be viewed as a group of building blocks called Function. A function is a subroutine that may contain one or more statements designed to perform a specific task.

A c program may contain one or more sections as follows:

  • Documentation Section consists of a set of comment lines giving the name of the program and other details.
  • Link Section gives instructions to the compiler to link functions from the system library.
  • The definition Section defines all symbolic constants.
  • Declaration Section declares variables outside of all the functions.
  • main( ) function section contains two parts:
  1. Declaration part declares all variables used in the executable part.
  2. The executable part has at least one statement, which is to be executed.
  • Subprogram Section contains all the user-defined functions that are called in the main function. User-defined functions are generally placed immediately after the main function, although they may appear in any order.

Some C Header Files:

<stdio.h> – Standard Input-output.
<stdlib.h> – Standard Library, memory allocation.
<stddef.h> – Defines several useful types and macros.
<stdint.h> – It defines exact width integer types.
<string.h> – Defines string handling functions.
<math.h> – Defines common mathematical functions.

C Language First Program:

#include <stdio.h> 
#include <stdlib.h>
int main( )
{
    printf("Hello world!n");
    return 0;
}

Output:

Hello world!

How does C program work?

Steps required in the execution of a typical C program:

  1. Creating a program
  2. Preprocessing and Compiling
  3. Linking
  4. Loading
  5. Execution

Creating a program:

This is the first step required in writing a C Program which is performed with an editor program such as code blocks. C program file names have .c extension.

Preprocessing and Compiling:

When a program is ready it will be compiled with the help of the compiler. The compiler translates the C program into a machine language code. In this case, the compiler can find the issue, a warning, or an error message if our program violates any rule.

Linking:

In this step, the linker links the code to missing functions. For example, our program may contain standard library functions that are defined elsewhere

Loading:

The next step of program progress is called loading. In this step, the loader loads the compiled program into computer memory for execution.

Execution:

At last, the computer executes the program that is loaded in the computer’s memory and output will be shown.

If you have any problem in solving your questions, then join our Telegram group or search @Learnsimply, we will help you.

Please write comments if you find anything incorrect in the Introduction to C Language lecture.

Leave a Comment

en English
X