Date post: | 15-Apr-2017 |
Category: |
Technology |
Upload: | akhilesh-maithani |
View: | 292 times |
Download: | 0 times |
C LANGUAGE
What is language
Akhilesh Maithani ([email protected])
The method of human communication, either spoken or written, consisting of the use of words in a structured and conventional way.
Akhilesh Maithani ([email protected])
What is programming language
A programming language is a formal constructed language designed to communicate instructions to a machine, particularly a computer.
Akhilesh Maithani ([email protected])
Type of programming languages
There are four type of programming languages
1- Machine Language 2- Assembly Language 3-High Level Language
Akhilesh Maithani ([email protected])
First Generation - Machine Language (code)
Machine language programs were made up of instructions written in binary code. This is the “native” language of the computer. Each instruction had two parts: Operation code, Operand
Operation code (Opcode): The command part of a computer instruction.
Operand: The address of a specific location in the computer’s memory.
Hardware dependent: Could be performed by only one type of computer with a particular CPU.
Akhilesh Maithani ([email protected])
Machine level language
It understands the language of the binary digits, 0 and 1.
We may write a program in whichever language we want, but it is finally converted into the language of 0s and 1s before it gets executed.
Writing a program in machine language is definitely very difficult.
It is not possible to memorize a long string of 0s and 1s for every instruction that you want to derive executed.
Akhilesh Maithani ([email protected])
Assembly language
Assembly language programs are made up of instructions written in mnemonics.
Mnemonics: Uses convenient alphabetic abbreviations to represent operation codes, and abstract symbols to represent operands.
Each instruction had two parts: Operation code, Operand Hardware dependent. Because programs are not written in 1s and 0s, the
computer must first translate the program before it can be executed.
Akhilesh Maithani ([email protected])
An opcode is a single instruction that can be executed by the CPU.
In assembly language mnemonic form an opcode is a command such as MOV or ADD or JMP.
For exampleMOV, AL, 34h
The opcode is the MOV instruction. The other parts are called the 'operands'.
Operands are manipulated by the opcode. In this example, the operands are the register
named AL and the value 34 hex
Akhilesh Maithani ([email protected])
High level language
Use statements that resemble English phrases combined with mathematical terms needed to express the problem or task being programmed.
Transportable: NOT-Hardware dependent. Because programs are not written in 1s and 0s, the computer
must first translate the program before it can be executed.
Akhilesh Maithani ([email protected])
Difference b/w high level and low level language
High Level1. Easily understood by humans
2. Uses English like words
3. Easy to locate and identify errors
4. Must be translated before the computer can understand it
Low Level1. Understood by computers
without the need for translation
2. Difficult for humans to read and understand
3. Take up a lot of space to write down
4. Its difficult to spot errors in the code
Akhilesh Maithani ([email protected])
Translators
All programs must be translated before their instructions can be executed.
Computer languages can be grouped according to which translation process is used to convert the instructions into binary code: Assemblers Interpreters Compilers
Akhilesh Maithani ([email protected])
Assembled languages:
Assembler: a program used to translate Assembly language programs.
Produces one line of binary code per original program statement. The entire program is assembled before the program is sent to
the computer for execution.
Akhilesh Maithani ([email protected])
Interpreted Languages:
Interpreter: A program used to translate high-level programs.
Translates one line of the program into binary code at a time: An instruction is fetched from the original source code. The Interpreter checks the single instruction for errors. (If an
error is found, translation and execution ceases. Otherwise…) The instruction is translated into binary code. The binary coded instruction is executed. The fetch and execute process repeats for the entire program.
Akhilesh Maithani ([email protected])
Compiled languages
Compiler: a program used to translate high-level programs.
Translates the entire program into binary code before anything is sent to the CPU for execution.
The translation process for a compiled program: First, the Compiler checks the entire program for syntax errors
in the original source code. Next, it translates all of the instructions into binary code.
• Two versions of the same program exist: the original source code version, and the binary code version (object code).
Last, the CPU attempts execution only after the programmer requests that the program be executed
Akhilesh Maithani ([email protected])
Error
A software bug is an error, failure, or fault in a computer program or system that causes it to produce an incorrect or unexpected result, or to behave in unintended ways.
Akhilesh Maithani ([email protected])
Types of error
There are basically three types of errors that you must contend with when writing computer programs:
Syntax errorsRuntime errorsLogic errors
Akhilesh Maithani ([email protected])
Syntax Error
Syntax errors represent grammar errors in the use of the programming language.
Common examples are:Misspelled variable and function namesMissing semicolonsImproperly matches parentheses, square brackets,
and curly bracesIncorrect format in selection and loop statements
Akhilesh Maithani ([email protected])
Runtime error
Runtime errors occur when a program with no syntax errors asks the computer to do something that the computer is unable to reliably do.
Common examples are:Trying to divide by a variable that contains a value of zeroTrying to open a file that doesn't existThere is no way for the compiler to know about these
kinds of errors when the program is compiled
Akhilesh Maithani ([email protected])
Logic errors
Logic errors occur when there is a design flaw in your program. Common examples are:
Multiplying when you should be dividingAdding when you should be subtractingOpening and using data from the wrong fileDisplaying the wrong message
Akhilesh Maithani ([email protected])
Introduction of c language
C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972.
It was designed by a man named Dennis Ritchie.C is popular because it is reliable, simple and easy to use.The origin of C is closely tied to the development of the
Unix operating system, originally implemented in assembly language on a PDP-7 by Ritchie and Thompson, incorporating several ideas from colleagues.
Akhilesh Maithani ([email protected])
Algol is an early high-level computer programming language devised to carry out scientific calculations.
BCPL (Basic Combined Programming Language) is a procedural, imperative, and structured computer programming language
Akhilesh Maithani ([email protected])
Features of C
The most important features of C Language are – Portability Modularity Flexibility Speed Extensibility Case Sensitive
Akhilesh Maithani ([email protected])
Portability
This feature refers to the use of C Language program on different platforms without any change of configuration. So C Languages program is independent of platforms.
Akhilesh Maithani ([email protected])
Modularity
Modularity is the most important feature of structured programming language.
This feature refer to the breakdown of large C Language into small modules.
Due to modularity features, complications of a program occurs in time and debugging of program will become faster.
Akhilesh Maithani ([email protected])
Flexibility
This feature refer to the programmer’s involvements and control on the language.
There are number of reserve words in C Languages which help the programmer to take control over of language and modified the structure of the program.
Akhilesh Maithani ([email protected])
Speed
As C Language supports the system programming so it is also called as middle level language. Due to this factor, the program of C Language is compiled and execute with more speed as compared to program of other high level language.
Akhilesh Maithani ([email protected])
Extensibility
In C Language Program, New Feature can be added at any time by programmer. So, C Language program is extensible.
Akhilesh Maithani ([email protected])
Case sensitive
C Language is a case sensitive language that is it can differentiate the character is either upper case or lower case. All type words either reserve words or user defined words are case sensitive.
Akhilesh Maithani ([email protected])
Steps in learning c
Alphabets Digit
Special Symbols
Constants Variable
KeywordsInstruction
s Program
Akhilesh Maithani ([email protected])
The C character Set
A character denotes any alphabets, digit, or special symbol used to represent information.
Valid alphabets numbers and special symbols used in C :-
Alphabets – A,B,…………………..,Y,Z a,b,………,y,z.Digits – 0,1,2,3,4,5,6,7,8,9Special Symbols - ~ ‘ ! @ # % ^ & * ( ) _ + = | \
{ } [ ] : ; “ ‘ < > , . / ?
Akhilesh Maithani ([email protected])
Constant
A constant is an entity that doesn’t change .Type of C constant :- (i) Primary Constant Integer Constant, Real Constant, Character
Constant. (ii) Secondary Constant Array, Pointer, Structure, Union, Enum, etc.
Akhilesh Maithani ([email protected])
Rules for Constructing Integer constant
An integer constant must have at least one digit.It must not have a decimal point.It can be either positive or negative.If no sign precedes an integer constant, it is
assumed to be positive.No commas or blank are allowed within an integer
constant.The allowable range for integer constants is -32768
to 32767.
Akhilesh Maithani ([email protected])
Rules for constructing real constant
A real constant must have at least one digit.It must have a decimal point.It could be either positive or negetive.Default sign is positive.No commas or blanks are allowed within a real
constant.
Akhilesh Maithani ([email protected])
Rules for constructing character constant
A character constant is a single alphabet, a single digit or a single special symbol enclosed within singh inverted commas.
Both the inverted commas should point to the left . For example, ’A’ is a valid character constant whereas ‘A’ is not.
The maximum length of a character constant can be 1 Character.
Akhilesh Maithani ([email protected])
Variable
A variable is an entity that may change, or an entity that may vary during program execution. Variables name are names given to location in the memory. These location can contain integer, real or character constant.
Akhilesh Maithani ([email protected])
Rules for constructing variable name
A variable name is any combination of 1 to 31 alphabets, digits or underscores. Some compiler allow variable name whose length could be upto 247 characters. Still, it would be safer to stick to the rule of 31 character. Do not create unnecessarily long variable names as it adds to your typing effort.
The first character in the variable name must be an alphabet or underscore.
No commas, or blanks are allowed within avariable name.
No special symbol other than an underscore can be used in variable name.
Akhilesh Maithani ([email protected])
Keywords
Keywords are the words whose meaning has already been explained to the C compiler.
The Keywords cannot be used as a variable names.There are 32 Keywords available in C which are as
follows :-auto double int structbreak else long switchcase enum register typedefchar extern return unionconst float short unsignedcontinue for signed voiddefault goto sizeof volatiledo if static while