C Programming Tutorial

Introduction to C

  • 'C' is a programming language that was developed in the early 1970s by Dennis Ritchie at Bell Laboratories.
  • It was designed for implementing system software and used for developing the portable application software.
  • It is one of the most popular languages.
  • C++ and Java are based on C programming which means that if you are well versed with C, then the above two programming languages can be learnt very easily.
  • It is primarily used for the system programming. It has the portability, efficiency and the ability to access the specific hardware addresses and low runtime demand on system resources which makes it a good choice for implementation of operating systems and embed the system applications.

Characteristics of C

  • C is a core language as many other programming labguages like C++, Java etc are based on it.
  • C is a portable language because if we write a C program on one computer we can run it on another one without little or no modification.
  • C is known as a robust language because it has a rich set of built-in functions and operators that help in writing complex programs.
  • It is a stable language as it was created in 1983 and since then it has never been revised.
  • It is a quick language as they make use of operators and data types which are fast and efficient.
  • It is an extensible language as it helps the user to add his own functions to the C library.
  • It is known as a structured language as the code is organized as a collection of one or more functions.
  • It supports loose typing because a character here can be treated as an integer and vice versa.
  • C has only 32 keywords which makes it easy to learn.
  • Pointers are supported in C as they refer to the computer memory, array, structures and the functions.
  • The features of assembly language and high-level language are combined by the C compiler.
  • It is a high level programming language which enables the programmer for concentrating on the problem at hand and not worry about the machine code on which the program would run.
  • There is an extensive usage of function calls.
  • It is well suited for structured programming which enables the users to think of the problems in terms of functions/modules.  It makes a complete program which in turn facilitates easy programming, debugging, testing and maintenance.
  • It is widely used for implementing end-user applications.

Structure of a C program

c program structure

Preprocessor directives: They contain special instructions which indicate how the program is prepared for compilation. Common preprocessor command is 'include' that tells the compiler to execute a program where some information is required from the specified header file.

Global declaration: It is a variable/function which is declared after the preprocessor directives and before the main() function.

Example

#include <stdio.h>
#include <conio.h>
int add (int a, int b);
void main()
{
     ...…...........
}


  • A C program contains more than one function where the functions are defined together as a group and all the statements are executed together. The statements are written logically and in a sequence for performing certain tasks.
  • The main() function is one of the most important parts of the program. It is a compulsory part of every C program.
  • All the functions in the program which include the main() function are divided into two parts -
    Declaration section: describes the data that will be used in the function.
    Statement section: contains the code that will manipulate the data for specified tasks.
  • A C program can have a number of functions depending on the number of tasks.  Any number of statements can be included in the function.