Introduction to C Programming

Introduction to C Programming

Here, you will come to know about the Introduction to C Programming Language. You will learn various concepts of  C language like how the compiler works, what is a program, and how we can let the machine to perform some tasks that are written in C Language. Let us learn from the beginning.


What is a Computer?

A computer is an electronic device which accepts data and treat it as input and process the data that is given as input and perform different tasks and gives some result as output.
A computer may be divided into two main parts.


1. Software
2. Hardware


What is a Software?

Software is a set of programs (a program is a set of instructions) that informs the processor to carry out certain tasks. Software may be either window based application or web-based application on which we conduct some logical, arithmetical, and functional tasks. For the creation of any software, there is the need of:


1. Analysis
2. Designing
3. Coding
4. Testing


Basically, software is classified into two types.

1. System software
2. Application software


What is System Software?

System software is a software on which we carry out any task. Actually, system software are the main types of software because, without this software, we cannot think of application software. for example- Linux, Unix, Windows XP, Windows 7, Windows 10, and so on.


What is Application Software?

Application software is the software that is created for end-users. Application software may be divided into two parts.

1. Window-based application software
2. Web-based application software

Window-based application software is that software that operates on the local system. for example- Notepad, MS-office, and so on.

Web-based application software is the software that operates on the servers that are situated far away from us. Websites, YouTube, etc are some examples of this software.


What is Hardware?

Hardware provides us the platform on which we can run different software. for example- Mouse, Keyboard, RAM, and so on.


What is Computer Programming?

Computer programming helps the computer to understand what to do next and how to do it. Programming gives the command to the computer system to do various tasks.

In programming, we give a set of instructions (programs) to the machine in the languages which are understood by the machine for performing various tasks like adding two numbers, dividing two numbers, and so on.


Introduction to C Language

C is a middle-level programming language which is used for general-purpose programming. C language was invented to write UNIX Operating system. It had been reading in assembly language.


Structure a of C Program

C is a structured programming language. So, the places of all the sections of the structure are intact.

1. Documentation section

2. File inclusion section

3. Definition section

4. Global declaration section

5. Main function section

6. Function section

7. Subprogram section


Documentation Section

The documentation section has the set of comment lines that are used for naming a program and other details. Note that comments are ignored by the compiler. There are two types of commenting.

1. Single line commenting

2. Multiple line commenting

Single line commenting is used for showing a single line comment. " // " double forward slash is used in C language to denotes single line comment.

Multiple line comment is used for showing the comments in multiple lines (more than one line). 

" /*    .....   */ " the comments are written in the place of ..... 
for example: Let us consider simple c programs

#include<stdio.h>

int main(){
  //  Hello Programmers! I am a single line comment.
  
  //  Program to add two numbers (It is also a single line comment).
  
  
  
  /*  
  
  Hello Techies! I am a multiple line comment. 
  I will go where ever I want to go in between.
  I may be here.
  I also may be here. It's my choice.         
 
 */ 
}

File Inclusion Section

In the File inclusion section, we include all the header files by using pre-processor director #include. The file inclusion section is also called the Link section because it links functions from the system library. 

These header files are those files whose functions need to be used in the programs. Let us consider simple c programs.

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
#include<alloc.h>

int main(){

  // ...some code here...

}

Definition Section

In the definition section, all the symbolic constants are specified using the preprocessor directive #define. For example - Let consider simple c programs

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

#define e 2.71        // e is Napier's constant.

Global Declaration Section

In the global declaration section, all the global variables which are going to be used by us in the program are declared. for example- Let consider simple c programs.

#include<stdio.h>
int i, j, k;                 // These are global variables

void main()
{
   int m, n, o;               // These are local variables
   // ...some code here...
}

Main Function Section

The main function section in C language is subdivided into two parts.

1. Declaration section

2. Execution section

In the declaration section of the main function section of C language, all the variables are declared that are being used within the main function in the program.

All the executable expressions or statements that process the declared data or variables are written in the execution section of the main function section of the C language.


Function Section

Function section in c language is divided into two parts.

1. Declaration section

2. Execution section


Subprogram Section 

The subprogram section contains all the user-defined functions.


Printf() Function

printf is a formatted output function of header file stdio.h (standard input output). 
Printf function in c language prints all the characters in a row as it is written in its first argument that is a string but there are many characters that cannot be printed by printf function on the screen.

They are known as non-printable characters and there are two types of non-printable characters.

1. Type specifiers

2. Escape sequence

Type specifiers are  %d, %f, %c, %ld, and so on. Escape sequence makes or control cursor i.e., it controls the movement of the cursor. They are \n, \t, \r, \f, and so on.


Scanf() Function 

Scanf is a function in c language that is used in a program to take input from the standard input device like a keyboard. Let consider simple c programs.

// program to print "Hello World"

#include<stdio.h>

int main()
{
   printf("Hello World !");
   return 0;
}

Output:

Hello World !

Let consider another simple c programs.

/* program to find
    addition of two numbers.  */

#include<stdio.h>

int main()
{
   int num1, num2;
 
   printf("Enter first number. \n");
   scanf("%d", &num1);
 
   printf("Enter second number. \n");
   scanf("%d", &num2);
 
   printf("Addition is %d", num1+num2);
   return 0;
}

Output:

Enter first number.
34
Enter second number.
30
Addition is 64

Take a look at the same program of addition of two numbers. Consider simple c programs.

// program to find addition of two numbers.

#include<stdio.h>

int main(){
  int num1, num2, sum;
 
  printf("Enter first number. \n");
  scanf("%d", &num1);
 
  printf("Enter second number. \n");
  scanf("%d", &num2);
 
  sum = num1+num2;
  printf("Addition is %d", sum);
  
  return 0;
}

Output:

Enter first number.
82
Enter second number.
37
Addition is 119

Labels

Post a Comment

1 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
julian said…
aston777 I have read so many articles or reviews on the topic of the