C Programming – Introduction

By | 21/10/2019

C is a general purpose procedural computer programming language. It was initially developed by Mr. Dennis Ritchie at Bell Laboratories, USA between 1969 – 1973. It was mainly developed to create Operating Systems (UNIX).

C is the most widely used computer programming language. It is machine-independent, structured programming language which is used extensively in various applications. C programming is considered as the base for other programming languages, that is why it is known as mother language. During the 1980s, C gradually gained popularity. Nowadays, it is one of the most widely used programming languages.

Features:

The main features of C language include low-level access to memory, a simple set of keywords, and clean style, these features make C language suitable for system programmings like an operating system or compiler development and many others. Some other great features of C are as follows :

  • Structured language
  • Procedural Oriented programming language
  • It produces efficient programs
  • Can handle low-level activities
  • Can be compiled on a variety of computer platforms
  • Codes are compiled using a relatively straightforward compiler to provide low-level access to memory.
  • Has low-level capabilities etc

Applications / Usage of C :

  • Operating Systems
  • Language Compilers
  • Assemblers
  • Text Editors
  • Print Spoolers
  • Network Drivers
  • Modern Programs
  • Databases
  • Language Interpreters
  • Utilities

Structure of a basic C Program :

A basic c program has a structure like this :

Headers
Main()
Return (Optional)

Main() [ also called main function ] has two basic sections in it.

Variable Declaration
Body

Have a look at the image below :

Image Courtesy : GeeksForGeeks

1. Headers / Header Files :

A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files.
The first thing to do while writing a c program is to include the Header files in a C program. Some popular and heavily used common header files are :

  • stdio.h (Standard Input Output)
  • conio.h (Console Input Output)
  • string.h (Defines string handling functions)
  • math.h (Defines common mathematical functions)

Syntax :

#include<stdio.h>
#include<conio.h>

2. Main() :

The next part of a C program is to declare the main() function. This part gets executed.

Syntax :

main() {
// body codes here
}

2.1> Variable Declaration :

Variable Declaration is the first thing to do in a main function. If you are using any variable(s), you have to declare it/them all in here before writing any further codes.

Syntax and Example :
int a;
int b = 10;
int c,d,e;
char name;
float f;

2.2> Body :

Next is body. Whatever you want to write (code), you have to write it here after your Variable Declaration.

Syntax and Example :

int main()
 {
     int a;
     printf("%d", a); 

3. Return Statement :

The last part in any C program is the return statement. The return statement refers to the returning of the values from a function. As main() itself is also a function so it has to return something. This return statement and return value depend upon the return type of the function. For example, if the return type is void, then there will be no return statement. In any other case, there will be a return statement and the return value will be of the type of the specified return type. This is why return is an optional statement.

Syntax and Example :

 int main()
 {
     int a;
     printf("%d", a);
     return 0;
 }

Or,

 void main()
 {
     int a;
     printf("%d", a);
 } 

Example of a basic C Program :

Code :

#include <stdio.h>
int main()
{
   // printf() displays the string inside quotation
   printf("Hello, World!");
   return 0;
}

Or,

#include <stdio.h>
void main()
{
   // printf() displays the string inside quotation
   printf("Hello, World!");
}

Output :

Hello, World!

Please write comments if you find anything incorrect, helpful, questions or you want to share more information about the topic discussed above.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *