C PROGRAMING : History , features , comments , syntax , data types , variables , operators



History :

C is a computer programming language used to do programming in operating system called UNIX. C was derived from B language . B language was adapted from BCPL(Basic Combined Programming Language) , which was developed by Martin Richards at Cambridge University.

C is an procedural oriented language developed by Dennis Ritchie in 1991 at Bell Laboratories.

Features of C :

  1. Procedural Oriented : In C every code or program is written with function or an procedure . That's why it is called as procedural oriented language . 
  2. Case sensitive : C is a case sensitive language because every upper case character and lower case character have different meaning . for example upper case character A and lower case character a have different meaning .
  3. Middle level language : C support the high level features and also supports to low level features , hence it is an middle level language . 
  4. Provide Translators : Everyone know that machine understands only 1 or 0 language . It is difficult to write and maintain code in machine language . Hence , c provide high level and low level language conversion. The translators are used for this conversion . Translators are the computer programs which performs this conversion and gives the machine level output properly . There are three types of translators 
  • Assembler 
  • Compiler 
  • Interpreter  
          Assembler are used to convert low level code in machine level code where compiler and interpreters are used to convert high level code in machine level code ..
The high level programs are know an source programs and machine level programs are known as object programs .


Basic syntax of c : 


//comment section                                              - comment section

#include<stadio.h>                                              - header files

#include<conio.h>                                               - header files

void main()                                                          - main function()

{                                                                           - curly braces open

  statements;                                                         - statements section

  getch();                                                              - linker between i/o and o/p screen

}                                                                           - curly braces close


  • Comment Section : This section is used to write user defined message for identification of code for user purpose only .This is not an executable part of program . It is only for user checking . Not visible in output screen . 
  • Header Files : This section is very important section in program . It stores all pre-define functions and statements inside it that we are going to use in program . stdio.h means Standard Input Output which stores standard library functions . conio.h means Connection Input Output which is connection between input and output .
  • Main function : The main execution of program stats here . Void means null . it does not stores any type of value .
  • Statements : The main program, code comes here . statements means the pre-defined loops , printf(), scanf(),etc. are going to use here . 
  • getch() : getch() is a function used to link input and output 

Comments in C :

As we shown in our previous post we can write own comments in c program . There are two ways to write the comments in a program i.e.

  • Single line comment : The single line comment is always written with //  . for example i have to write my program name so , I will write //program for addition of two numbers .
  • Multiline comment : The multiline comment is written with /*.......*/ For example i want to write multiline omments so I will write 
             /*program for addition of two numbers 

               program for accepting values from user*/

Data types in c : 


In C programming , every variable have associated data type . Data types means which type of date we are storing in a variable or using  in  program . Each data type requires some specific amount of memory for storage . C has some basic data type i.e. 
  • int : This data type is used to store integer . For example 1 2 3 . It requires 4 bytes in memory.
  • char : This data type is used store characters in memory . It requires 1 byte in memory .
  • float : this data type is used to store single decimal pointing integers . It requires 4 bytes in memory .
  • double : This data type is used to store double decimal pointing integers . It requires 8 bytes memory .
 


Variables in C :


Variable used to store any value acording to its declared data type .

consider following example :

int a=10;

In this example , int is a data type which is used to declare or store integers through variable a . I have given variable name as a and stored 10 value ina variable i.e. variables are used to store any other value according to its data type.

Rules for naming the variables :

There are certain rules to give any name to an variable . It should be according to below given rules .

    • Variable name should be start with character or underscore .
    • cannot start variable name with number or digit .
    • Variable name with upper case and lower case have different meanings . We can take upper cases as well as lower cases in variable naming.

Operators in C :-


Let's se an example ,

         c=a+b

where , c=a+b is an expression 

             c , a, b are operands 

             = + are operators 

Hence , operators are the symbols used to solve an expression .

An expression is an combination of operators and operands . 

There are multiple types of operators as given below .

  1. Arithmetic Operators 
  2. Relational Operators 
  3. Logical Operators
  4. Conditional Operator
  5. Bitwise Operators
  6. Assignment Operators
  7. Increment and decrement operators

1. Arithmetic operators : 


This operator is used to perform basic operations like addition subtraction etc.

It includes 
+ : performs addition
-  : performs subtraction
/  : performs subtraction
%  : returns remainder after division
  

Example :Write Simple C program without accepting values from user.


#include<stdio.h>
#include<conio.h>
void main()
{
int a=20,b=10,c;
c=a+b;
printf("addition is %d",c);
c=a-b;
printf("Substraction is %d",c);
c=a/b;
printf("Division is %d",c);
c=a%b;
printf("remainder after substraction is 5",c);
getch();
}

Example : Program with accepting values from user


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter value for a : ");
scanf("%d",&a);
printf("Enter value for b : ");
scanf("%d",&b);
c=a+b;
printf("addition is %d",c);
c=a-b;
printf("Substraction is %d",c);
c=a/b;
printf("Division is %d",c);
c=a%b;
printf("remainder after substraction is 5",c);
getch();
}