Introduction to C - Code Is Interest

In this tutorial, you will learn about the basics of the C programming language. 

Introduction :

  • The language C was developed in the early 1970s by Dennis Ritchie to be used by UNIX operating system.


  • It was named ‘C’ because many of its features were derived from an earlier language called ‘B’.
  • Although C was designed for implementing system software, it was later on widely used for developing portable application software. Like Adobe Systems, Google Applications, Mozilla Firefox, MySQL Server, etc.

Characteristics of C programming :

C is one of the most popular programming languages in the world. 

1. Simplicity:- 
🠊C has the richest collection of inbuilt functions, keywords, and data types. Also, it follows a structured approach so it is easy to learn also.

2. Clarity:- 
🠊The keywords and library functions available in C resemble common English words thus it helps to improve the clarity of the program.

3. Portability: – 
🠊By the term portable, we mean computer independent. The program made in C can be made to run on different machines thus increasing the efficiency of the program.

4. Modularity: –
🠊The programs made in C can be easily divided into small modules with the use of functions. This feature helps to increase the understandability of the program.

5. Extensible:- 
🠊C is an extensible language as it enables the user to add his own functions to the C library.

6. Small size:- 
🠊C has only 32 keywords. This makes it relatively easy to learn compared to other languages.

Structure of C program:-



Documentation Section:-
  • The documentation section consists of a set of comment lines, giving the name of the program, the author, and other details, which the programmer would like to use later. The comments can be written in two ways:

a) Multi-line comment
/* This is a multi-line comment */

b) Single-line comment
// This is a single-line comment
Link Section:-
  • The link section provides instructions to the compiler to link functions from the system library.
  • If we want to access the functions stored in the library, it is necessary to tell the compiler about the files to be accessed. This is achieved by using the preprocessor directive #include as follows:

#include<filename>

  • Where filename is the name of the library file that contains the required function definition. Preprocessor directives are placed at the beginning of the program. Some of the examples are:

#include<stdio.h>
#include<conio.h>
#include<math.h>
Definition Section
  • The definition section defines all symbolic constants.
  • A #define is a preprocessor compiler directive and not a statement. Therefore #define lines should not end with a semicolon.
  • Symbolic constants are usually written in uppercase so that they are easily distinguished from lowercase variable names.
  • #define instructions are usually placed before the main( ) function.

#define YEAR 2014
#define  PI 3.14
main( ) Function Section
  • Every C program must have one main( ) function section. This section contains two parts, the declaration part, and the executable part.
  • The declaration part declares all the variables used in the executable part.
  • There is at least one instruction in the executable part.
  • These two parts must appear between the opening and the closing braces.
  • The program execution begins at the opening brace and ends at the closing brace. The closing brace of the main function section is the logical end of the program.
  • All the statements in the declaration and executable parts end with a semicolon (;).
Subprogram Section
  • The subprogram section contains all the user-defined functions that are called in the main functions. User-defined functions are generally placed immediately after the main function, although they may appear in any order.

Sample Program 
// A simple C-Program to print a message
#include<stdio.h>
#include<conio.h>
void main()
{
/* my first program in C */
               printf(“Welcome to Code is interest! \n”);
}


Let us look various parts of the above program:
▶ The first line of the program is a single line comment, giving the description
about the program as well as author’s name.
The next two lines are #include <stdio.h> and #include <conio.h> which are
preprocessor command(s) which tells a C compiler to include these files before
going to actual compilation.
The next line void main() is the main function where program execution begins.
The next line /*...*/ will be ignored by the compiler and it has been put to add
additional comments in the program.
The next line printf(...) is another function available in C which causes the
message "Welcome to Code is interest!" to be displayed on the screen.


Post a Comment

0 Comments