C language History of c language



Download 75.01 Kb.
Date conversion28.01.2017
Size75.01 Kb.





C language

History of C language:-

The root of all modern language is ALGOL, which is introduced in 1960.

In 1967, BCPL language is introduced by, International Group. B language is invoked in 1970 by, Martin Richards.

Traditional c is introduced in 1972 by, Dennis Ritchie. In early of 1978 the K&RC language is invoked by, Kernighan and Ritchie. The ANSI C language is introduced by ANSI committee in 1989. In 1990 ISO committee introduce ISO C language which is used now a day.

First of all C language is invited in “BELL LAB” in 1972 by, Danish Ritchie.

WHAT IS C?

C is a System Programming language. System which means that the operating system; which is used to operate the computer, like linux,unix, windos, etc… programming which means that a structure or a syntax. The programming is used to create the proper language with the proper format. Through this format we can create the system with the proper way. Language is used to invoke the programming in the proper way with sutable and understable structure. The language in the operationg system has two types.



  1. Middle level language

  2. High level language.

This levels of the languages are based on the use of the structure and the system which is saports. In middle level language C language is introduces. And in high level language there is java and c++.

In short, C in the programming language which is use to create the proper system;with a sutable structure and which is easy to implement.

Now c language is consider as the platform deepemdant language.

Features of c language: (or) c tokens:

In a passage of text, individual words and punctuation marks are called tokens. In other words token is the spacification of the perticuler fenomina.

In c language the smallest individual units are known as tokens.

In c programming we mainly have 5 tokens; which are as ander


  • Constant

  • Operators

  • Identifier

  • Data type

  • Key word

Let us see all this tokens in details.

  1. Identifier:-

Identifier is used to identify the variables. It helps compiler to identify the proper value of the variable.identifiers refers to the name of the variable, function and array. These are user define name and consist of a sequence of letters and digits, with a letter as first character.

Rules of identifiers



  • First character must be alphabetic or underscore.

  • Only first 31 character are significant.

  • Can not use key-word as identifier.

  • Must not contain with space.

Example:

‘A’ ; “hello”; “q123” ; ‘r’ etc…



  1. Key word:-

Key words are the words which has a fixed meaning. In c compiler key words has the specific meaning. Every keyword has a fixed meaning of that word; we can not change that meaning of that word. Keyword serves as basic building blocks for program statements.

We have 32 keywords in C language; all are shown bellow.



Auto

Break


Case

Char


Const

Continue


Default

Do


Double

Else


Enum

Extern


Float

For


If

Goto


Int

Long


Register

Return


Short

Signed


Sizeof

Static


Struct

Switch


Typedef

Union


Void

While


Volatile

Unsigned


All keywords must be return in the lowercase. If we want to use this keywords we must have to open the two header files. This are shown bellow.

#include

#include

All this type of keywords are stored in above two header files.



  1. Data type:-

Data types are type of the data foe wich we are going to creat the program. This type are the type which allocates the memaroy according to the user requiermnt. Data types provides the corresponding memory to the veriables.

Mainly thir are four data types.



  • int:- this data type gives 2 byte of the memory from the main memory to the corresponding variable.

This data type includes all numeric values like 0,8,15,9,-95,98,-5,-6,10,etc…

  • float:-this data type gives 4 byte of the memory from the main memory to the corresponding variable.

This data type includes all real values like 2.03,0,0.5,-0.8,-94.02,6,etc…

  • char:-this data type gives 1 byte of the memory from the main memory to the corresponding variable. This data type includes all the alphabetic characters like ‘A’,’Y’,”HELLO”,’E’,etc…

  • dounle:- this data type gives 8bytes of the memory from the main memory to the corresponding variable. This data type includes the int values which are the out of the int data type. This data types are also known as long int.

  1. constant:-

constants in C refer to fixed values that do not change during the execution of a program. C supports several types of constants are as shown bellow:-

Let us see all that types in detail.



  1. Numeric Constant:- this type of constants include all the numeric values constant.

  • Decimal :- includes combinational set of digits “0 to 9”;which is preceded by an optional sign + or - . like 235,-95,0,520,etc…

  • Octal decimal:- includes combinational set of digits “0 to 7”. With a leading digit as 0. Like 025,0264,04567,0,etc...

  • Hexadecimal:- includes combinational set of digits “0 to 9”and ‘A to F’. it is also includes a sequences on 0x or 0X. like 0X2,0X,58749B,FA254,etc…

Integer constants are denoted by “%d”.

  • Real constant (OR) float constant:- this includes the set of all real values with both positive and negative. This constant are denoted as “%f”. like 2.05,0.02,0.69,0,2.3,98.5,

-9.05,87,87.25,etc…

  1. Character constant:- this type of constants include all the character values as constant.

  • Character constant:- this type of constant includes all types of single characters as constant. It is any constant which includes the any alphabetic character.

  • It is denoted by %c.

  • It is identify by single coder (‘ ‘) . like ‘a’,’v’,’H’,’O’,etc….

  • String constant:- this type of constant includes all types of constant that contains the string as a constant. It is collection of single character together and make a string as a constant.

    • it Is always denoted by %s.

    • it is identify by double coder(“ “).like “hello”,”name”,”how are you?”,etc…

  1. Operators:- operators are the signs which indicates compiler to do some action or some specific operations on the values which is given by the user to perform on it. this sign helps compiler to do any kind of meathematical and logical operations on the values or on the variables. The variables on which the operation may have done are known as operand. Mainly the operators are of the different 8 types. All that types are different from each other by operation which it performs.

Types of operators :-

  1. Arithmetic operators

  2. Relational operators

  3. Logical operators

  4. Assignment operators

  5. Increment and decrement operators

  6. Conditional operators

  7. Bitwise operators

  8. Special operators

Let us take a look on all that operators in detail.

      • Arithmetic operators:-

This type of operator supports all the mathematical operation among the operand. The types of arithmetic operators are given bellow:-

Arithmetic operators

Meaning of it

+ (Addition)

To do Addition of both the operators.

- (Subtraction)

To do subtraction of the operators.

* (Multiplication)

To do multiplication of the operators

/ (Division)

To perform the division task on the operand.

% (Module)

Returns the value which is remains after dividing one value by one.

Syntax:-

Operand01 arithmetic operator operand02

Like:-

x+y; x-y; x*y; x/y; x%y;…

      • Relational Operators:-

This type of operator are gives the relation between two operands. It plots the relation among the operands. The types of it are as shown bellow.

Relational operators

Meaning of that operator

<

Larger than it

>

Smaller than it

<=

Larger then it or equal to it

>=

Smaller then it or equal to it

==

Equals to the value

!=

Is not equal to the value

Syntax:-

Operand01 relational operator operand02

Like:- xy; x<=y; x>=y;

  • Logical operators:-

logical operators are use to establish some type of logic among the conditions. This type of operators are use to find the value between the conditions. This operator is always use with the conditions. If we want to find some logic between the conditions we must have to use logical operators. There are three types of the logical operators all that are as shown as bellow:-

1… logical and [$$]

2… logical or [||]

3… logical not [!]

Let us take a look on all that in brift.



  1. Logical and [$$]:-

Logic and are use to compare two condition. If both the conditions are true or non-zero then and only then the result of the operator will be non-zero.

Syntax:-

$$

Like:-


a<20 $$ a<10;

  1. Logical or [||]:-

Logical or use to compare two conditions. If etlist one of the condition is true or non-zero then result of that condition is true or non-zero.

Syntax:

||

Like:


a<20 || a<18

  1. Logical not [!]:-

Logical not is use to find one condition. This operator is used to reverse the result of the particular condition.

Syntax:

!

Like:


!a=20;

  • Assignment operator:-

Assignment operator is used to assign the value of the variable. This operator stores the value of the right hand side of the operator into the value of the variable which is left hand if the operator.

Assignment operator first evaluate the expression of the right hand side of the operator and stores the value to the variable of the left hand side of that assignment operator.



Syntax:

X=a+b;

This operator first add the value of b into the value of a and then store that value into the variable X.



  • Increment and decrement operator:-

This operator is used to increase or decrease the value of the variable. This operator is the unary operator. This operator is work only on the one variable at the same time that’s why this operator is known as unary operator. This operator have two types.



  • Prefix operator:-

The operators which are include before the operand is known as prefix operator.

++ and - -

This operator first increases or decreases the value of the operand and then assign that value in that operand. So first the prefix operand is run and then the assigned operand is run at the time of axicution.

Example:-

Input:-


B=3;

A=++B;

Output:-


B=4;

A=4;

In This program the value of B is first increment by 1 and then it store into the value of the variable A.

  • Postfix operator:-

The operator which are include after the operand is known as postfix operator.

++ and --

This operator first assign the value of the operand and then increment or decrement the value of that operand. So first the operand is assign and them the postfix operator is run at the time of the execution.

Example:-

Input:-


B=3;

A=B++;

Output:-


A=4;

B=3;

In this program the value of the B is stored into the A and then the value is increment by 1.



  • Conditional operators:-

This operator is also known as TURNARY OPERATOR. This operator is use to chake the condition among the two variables or between the two operand.

Syntax:-

Condition ? result 01 : result 02

This operation works like this way. First check the condition, if the condition is true then execute the result 01 and if the condition is false then the result 02 will be execute.

Example:-

5>3 ? a : b

First check the condition. It is true so returns the result a.


  • Bitwise operators:-

Bitwise operator is used to do bit manipulation on the operand. This operators are as shown bellow.

Operator

Meaning

$

Bitwise AND

|

Bitwise OR

^

Bitwise exclusive OR

~

One’s compliment

<<

Shift left

>>

Shift right



  • Special operators:-

This operator is use to fulfill some special requirements.

Operators

Meaning

( , ) coma

Uses to differ on operand from other as well as to differ on condition from the other.

Like:- int a,b;

Size of

It is used to find the memory which is stored by the variable or by the data type.

Like:- int n,m;

. m=size of(n)

Structure of c language:-

Some important notes to have a look while constructing a c program.



  • It must be save by .c

  • It must have header fiels, getch(), and clrscr().

  • Program is run by [ctrl+F9]

  • Program is compile by[Altr+F8]

Structure of c program:-

As shown in the structure there is main 4 parts of the c structure. This are as show in bellow.



      • Header file section

This section is use to include or open the header file which are important to run the programs of c program. Some important function for excicution are stored in that header files with its definations.

#include

#include

      • Main section:-

Main section is the heart of the c program. The logic and operations which are written into the main section only and only that part is executed. Main part is the part which are important for the execution of the program , line by line.

      • Clrscr section:

This is a special function which is use in the programming. This is a function which is store in the conio.h file. This file is use to clear the output of the earlier program. So it clear the output screen before the execution of the current program.



      • Getch section:

This section use the getch function. This function use to close the execution of the program. This program declair compiler to stop the execution of the program and come back to the blank program or use to tell to get the input screen back.

In the structure of c program there is two other important functions are use to build the c programs.

Printf( );

This funtion is use to display something on output screen. If we want to display some notes on my output screen; I have to use printf function for the printing of that part must be written between “ “ in the breakats of print section.

Scanf( );

This function is use to scan the value from the user. This function is use to get value from the user at the run time of the program and execute all the program according to that value which is given by the user. So this function is use to get value of variable at run time and make program on the choice of user.

There is two another attributes to make the program attractive. This are [ “\n” ] and [ “\t” ].

“\n” :- is use to print the value in new line at the time of run or on the output screen.

“\t”:- is use to give the space of one tab space between two words.

Both of this are must be written in between double cordon [“ “].

Input:-

Output:-


Ch 02:


Simple PROGRAMS OF C…

PRO 01


WRITE A PROGRAM TO FINE THE SUM OF TWO VALUES WHICH IS GIVEN BY THE USER:

INPUT:-



OUTPUT:-

PRO 02:


write a program of interest calculation.

input:-



output:-

Pro 03:


Write a program to find the area of circle.

Input:


Output:-


Home task



  • Write a program to find a+b; a-b; a/b; and a*b.

  • Write a program to find the area of triangle and area of cube.

  • Write a program to find the distance.

  • Write a program in which user entered the amount of the money and convert it into the rupees and paisa.

  • Write a program in which user entered the total days and display the months and remaining days.

Ch 03:


Conditional statement:

What is conditional statement?

Conditional statements are the statement which are use to check the condition. According to that condition the task or the program will be executed. The condition may be true or false and according to that the logic may run.

There are main two conditional statements.



      • If … else…

      • Switch case.

Now let us see how it may be done.

    • If …. Else..:-

In this type of conditional statement we check the condition with the help of if statement. It will run the logic which we entered into the body part of if statement when the condition is true. And execute the body part of else section or it may be denote as a default statement.

If...else… statement may be grouped into the 3 parts.



  • If…eles..

In this type of statement there is only two options are avalabel for the execution. The condition may be true or false. There is no other option for the compiler to execution.

Syntax:

If(condition)

{

Body part;

/*will be executed if and only if the condition is true*/

}

Else

{

Body part;

/*will be executed if the condition is false*/

}

let us take an example of if…else…

pr04: write a program for even or odd values.

Input:-


Output:-


Example 02:-

Write a program to find max between two numbers.

Input:


Output:-




  • Else if..

In this type of statement the compiler first check the main condition which is written with the if and if it is false then it will go to the else section and wil execute if the condition which is written with the else part.

Syntax:

If(condition)

{

Body part;

/*will execute if the condition is true */

}

Else if(condition)

{

Body part;

/*will execute if the first condition is flase but the second

If condition is true.*/

}

Else

{

Body part;

/*will be executed if all the above conditions are

False*/

}

Let s take an example for it

Write a program for given no is positive, negative or zero.

Input:-



Output:-



  • Nested if… else…

This type of if else statement use to check the condition in the condition it means that in this section the program have main codition with the if nd if it is true then it will go to the body part, and in that body section there is another if…else… statement; and if the main codition is false then in the else section there is one anuther if… else… statement in that part.

Syntax:

If (condition)

{

If(condition)

{

}

Else

{

}

}

Else

{

If (condition)

{

}

Else

{

}

}

Let us take an example:

Pr05: write a program to find the maximum number among the three numbers.

Input:





Output:




  • Switch case:-

This statement is the one more type of conditional statement. In this type of statement is check the condition [if condition] without writing it. let us take a simple example of it, if we prase the key like “k” in the keyboard then on the output screan it will print the character “k”. this logic is known as switch in which some specific task is ocure at the specific choice of user.

Syntax:

Switch( variable on which we are performing switch )

{

Case 1:

Logic 1;

Break;

Case 2:

Logic 2;

Break;

:

:

Default:

Logic;

}

In this fenomenan user enter its choice; according to its choice the case was selected and the logic of that case will be executed. Once the case is selected and after executing its logic we use the keywoard break; which is stance for braking or stoping the execution of the program as soon as the compiler read the break key-ward.



Let us take an example for that:

Write a program if I prase 1 then adition, 2 for subtraction, 3 for multiplication and 4 for divistion.

Input:




Output:




  • Nested switch:-

It represents the switch within the switch. Which mean that in the case of the main switch there is another switch case statement.

Syntax:

Switch( variable on which we are performing switch )

{

Case 1:

Switch( variable on which we are performing switch )

{

Case 1:

Logic 1;

Break;

Case 2:

Logic 2;

Break;

:

:

Default:

Logic;

}

Break;

Case 2:

Logic 2;

Break;

:

:

Default:

Logic;

}

Ch :04


Loop

What is loop?

Loop is the different type of the c language in which the condition is use in the different mener. If we want to perform the same type of logic till numbers of times then the concept of loop is comes to the mind. The loop executes the program from the given values which is stands for the point at which we want to start the exicution; and excite the body par till the condition is true if the condition is false then it will be through out from the loop. in the any loop structure there is the main two parts or the segments; help of which we can simply creat a loop. It was body of the loop and control statement. Body of the loop is the segment in which the logic which we have to do for the several times is being return and control section is the section in which we write the condition to control the loop. So we can say that the loop is based on the condition. The loops may be diided into the two parts . all this parts are dependent on whether the condition is check in the program for controlling the loop.



Entry control loop which means that the loop which has the control section at the entrance of the loop. In this type of the looping structure first the condition is being checked , if it is true than and than the body part of the loop is executed.

Like: for loop, while loop.



      • Exit control loop.

Exit control loop which means that the loop hase control section as the exit or at the end of the loop. Which means that the condition is check at the end of looping structure so the body of the loop will be executed etlist once in the program then it check the condition if it is true then it will run the body section again.

Like: do…while loop.

Lets see all them in the detail.


  1. For loop:-

For loop is en entry control loop.

Syntax:


For ( initialization ; condition ; increment of decrement)

{

Body of the loop;

}

In this syntax initialization which means that the starting point of the loop. That point desid the starting value for the loop. Condition which means the condition which desied the ending point of the loop. Increment or decrement are the operators which desied that whether the vakue is increasing from the starting point to the ending point or the value is decresing from thr ending point to the starting point.

Write a program

Input:


Output:


Write a program

Input:

Output:




  1. Nested for loop:-

Nested for loop which means that the loop within the for loop. It depends on the first for loop and work as the body part of the first for loop

Syntax:

For ( initialization ; condition ; increment of decrement)

{

For ( initialization ; condition ; increment of decrement)

{

Body of the loop;

}

}

Write a program for

Input:



Output:



Write a program for the petarn:

Input:



Output:



  1. While loop:-

This is also the entry control loop. Which has different strucutr or the different syntax from the for loop but the purpose of the use of that loop is same. In the strutuer of this loop all the three sections initialization, condition and increment or decrement are call or define in the different part of the program.

Syntax:

Initialization;

While (condition)

{

Body of the while;

Increment or decrement;

}

Write a program.

Input

Output:




  1. Do while loop:-

This loop is exit control loop; so it will check the condition at the end of the loop. So through this looping structure we are able to execute its body parts etlist one time, then it checks the condition if it is true then and then only the body of the loop is again executed.

Syntax:


Do

{

Body of the loop;



} while( condition );



The database is protected by copyright ©ininet.org 2016
send message

    Main page