An Introduction to C Programming

An Introduction to C Programming

by Sanjay Nair February 17, 2018

C Language Introduction

  • The language C is a Procedural level language.
  • This language was developed by scientist Dennis Ritchie between 1969 and 1973.
  • The main objective of developing C was to write an operating system.
  • Some features of C language are that it can access low-level memory, it has simple set of keywords, it has a clean style
  • and all these features make C the favorite choice for system programming and compiler development.
  • Most of the programming languages have in one way or other borrowed the syntax/features from C language.
  • Some examples of programming languages that have borrowed syntax styles from C are Java, PHP , Javascript etc.

 

A small C Program

1) A compiler

  • Before we start writing C programs, we need to have a C compiler that can compile and run our programs.
  • There are lot of C compilers available online, using which you don’t need to install a compiler on your computer.
  • Egs of online compilers are http://ideone.com/, http://codepad.org/ etc
  • If you need to have a permanent compiler installation of a compiler on your computer, then we would recommend CodeBlocks and Dev-CPP.
  • For linux version also Code Blocks can be used as a compiler.

 

Egs of a C Program

 

Here is the first C Program

 

 

On running:

Output:

First C Program

Let us understand this problems line by line

First Line [ #include <stdio.h> ]

  • All statements that begin with # is processed by a preprocessor in C language and a preprocessor is a program which is invoked by the compiler.
  • Simply speaking, a preprocessor takes a C program and converts it into another C program.
  • This converted C program does’nt have any lines beginning with # as those lines are processed by the preprocessor.
  • In the above program , the preprocessor copies the preprocessed code of stdio.h into our sample program.
  • The statements ending with .h are called header files in C.
  • Such header files contain declaration of functions. In the above program we need stdio.h in order o use the function printf().

Second Line [int main(void)]

  • This is the starting point from where the execution of compiled C program begins.
  • In C programming, the execution generally starts with the first line of main().
  • The void written inside main indicates that this function does not have any parameters.
  • The above function main() can be written such that it accepts parameters.
  • We will get into the details of such a function in a later post.
  • The data type int indicates the return type of the function main().
  • The value returned by the main function indicates the termination of the program.

3rd and 6th Line: [ { and } ]

  • In C programming language the curly brackets indicate scope and they are mainly used in functions and control statements like if, else and loops.
  • All functions must start and end with curly brackets regardless of the number of lines inside them.

4th line  [ printf(“First C Program”); ]

  • The function printf() is a standard library function and it is used to print somthing on the standard output.
  • The semicolon used in the end indicates termination of the statement.

6th Line: [ return 0; ]

  • The return statement returns the value from the main() function.
  • This acts as an indication for the operating system that the program is about to terminate.
  • If the return value is 0 then it means successful termination of the C program.

If you find any correction in the above tutorial, then kindly mention it in the comments section below.

You may also like

Leave a Reply