A programming language is designed to help in processing of certain data and to provide useful information to the user. There are lots of programming languages today that satisfy different needs of the user. For example: C, C++, Java, SQL, HTML, JavaScript etc. It helps to write a sequence of instructions that the computer can understand.

Actually, computer understands only machine level instructions i.e. 1 and 0. But it is really impossible to write a program using these binary digits. So, high level languages came into existence where the programmer can write the instructions using English like statements. And the Compiler takes the responsibility to convert a high level program into machine level instructions. 

C language came into existence in 1972 as a high level language. It was developed by Dennis Ritchie at Bell Laboratories. It is one of the most popular programming languages today. C can run under a number of operating systems including MS-DOS. It is well suited for structured programming.

It is a robust language with number of functions and operators to handle any complex program. Both system software and business packages can be developed using it. C is highly portable i.e. C program written for one computer can be run on another without modification.

Basic structure of C programs:

A C program may consist of one or more following sections:

1) Documentation section – It gives the name of the program, the author and any other details about the program.

2) Link section – It provides instruction to the compiler to link functions from the system library.

3) Global declaration section – Global variables are declared in this section.

4) Main() function section – Every C program must have one main() function. The program execution begins at the opening brace and ends at the closing brace of main function section.

5) Subprogram section – It contains all the user-defined functions that are called in the main function.

Defining various components of C:

Keywords – they have fixed meanings and these meanings cannot be changed. Ex: auto, break, case, int, long

Identifiers – these are user defined names consists of a sequence of letters and digits. Name of variables, functions and array are its example.

Constants – It is the fixed value that does not change during the execution of a program. It can be integers, real numbers, characters, strings

Variable – it is a data name that is used to store a data value. It may take different values at different times during execution.

Data types – It represents which type of data being used in a program.

Operator – it is a symbol that tells the system to perform mathematical or logical calculations.

Expression – it is a combination of variables, constants and operators arranged as per syntax of language.

Printf() – it is a library function used for printing results.

Scanf() – it is also a library function that is used to read input data from the user.

<stdio.h>--standard input-output header file must be included at the beginning of a program.

Main() – It is a user-defined function which tells the computer where the program starts.

Function – It is a self-contained block of code that performs a particular task.

Sample C programs:

/*Program displaying a number*/
#include <stdio.h>
#include <conio.h>
int number;
number = 100;
printf(“The number is %d”, number);

The number is 100

Explanation :

/*Program displaying a number*/ -- It is a comment line to represent any information about the program. Anything between /*…*/ is not executed.
#include <stdio.h>-- It instructs the compiler to search for a file called stdio.h and place its contents at this point in the program. stdio.h contains standard I/O library functions like printf() .

#include <conio.h> --It instructs the compiler to include conio.h file in the program. This header file declares several useful library functions for performing console input and output from a program.

main() -- This is the main function from where execution begins. Every program must have only one main function. Main function body is defined within two braces {…}.

int number; -- It declares a variable called number which is integer type. The maximum value that an integer type can hold is 32767. Every C statement must be ended by a semicolon (;). All variables must be declared prior to their use in the program.

number = 100; -- It initializes the variable number with the value 100. = is an assignment operator.

printf(“The number is %d”, number); -- The last statement prints out the value of number in integer format.

getch(); -- this function reads a character directly from the console without echoing . And it is required to see the output.

This was a very simple C program. Much more about C is coming in my next articles…

Like it on Facebook, +1 on Google, Tweet it or share this article on other bookmarking websites.

Comments (0)

There are no comments posted here yet