
UNIT-2 Programming language 'C' Contents Types of Programming Languages : 1. Machine-level, 2. Assembly, 3. High level languages. Features of C : basic concepts, structure of a C program, declarations, Data types : Variables, expressions, conditional expressions. Operators : Assignment, Arithmetic, Relational, Logical, Increment and Decrement, Precedence of operators, Type conversions, I/O Function : scanf and printf functions. Programming Language A programming lang. is the lang. used to communicate instructions to the machine i.e. Computer. Ex. C, C++, Basic, Cobol, Pascal Fortran. JAVA, JAVA Script. VB, VB .NET PHP C# Python SQL Types of Programming Languages 1. Machine-level Languages 2. Assembly Languages 3. High level Languages Machine-level or Low Level Languages series of sequence of 1 & 0 as instructions. This is the only lang. understand by computer. These are machine dependent lang. Machine language instructions has two parts 1. Opcode ( Operation Code): Tells the computer which operation to perform. 2. Operand : It tells where to find or store the data to be manipulated. M a c h i n e C o d e s Advantages Of Machine Languages Only languages understand by computer Simply understandable for computer It does not require any translator to translate code. Limitation Of Machine Languages Difficult for user All opcode and addresses must remember Error finding is difficult as it is written in 0&1 Writing program it takes huge time. Assembly Language Low Level programming developed to overcome inconveniences of machine lang. In assembly lang. operation codes and operands are given in the form of alphanumeric symbols instead of binary nos. 1&0. These symbols are also called as mnemonic codes. This is also machine dependent. Assembly language programming Are translated into executable machine code by using assembler. Assembly Machine Code Assembler language program (Object Code) Assembly Language Program High Level Lang Designed to enable people to write program Easily & in their own native lang. i.e. English. Uses English/ mathematical symbol. Deals with arrays, variables, objects, arithmetic etc. HLL Progam must to translated into machine language by using compiler or interpreter. The first HLL designed in 1950s Ex. C, C++, Basic, Cobol, Pascal Fortran. JAVA, JAVA Script. VB, VB .NET Scripting Language These lang. can be executed without explicit compilation and linking. Scripting lang. are interpreted rather than complied. These are used in Web Development for validation control etc. E.g. Java Script, VB Script, ASP, JSP, PHP, Perl, Ruby, Shell, Phyton. Advantages It is easier to write code. Editing & running scripting code is fast. Limitation : Slower Harder to debug as no development environment is available by default. All scripting lang. are not supported by all the systems. Natural Languages Natural lang. is the lang. which acquired naturally. This is typically used for human communication No training is required for these lang. E.g English, French, Chinese etc. Characteristics of Good Programming Language Simple & readable Portable : Language should be machine independent General: Programming language should allow writing wide variety of programs so that the programmer can become expert in many languages. Widely Available Efficient Abstract Selecting Programming Language The targeted platform where the programming Will run The elasticity of a lang. in which new features can be added to the existing programming The performance Community support. Environment: Platform, Web, Network Scientific, General etc. Subprogram (function) Suppose we want to add two nos. then we have to write programming For it., Again suppose we want to perform the subtraction then again we need to write the same code. So it will increase the programming Size. To avoid this we can write subroutine(subprogram) which is a part of main program. These are nothing but the set of instructions to do the specific task send result back to main program. Some HLL language FORTRAN : FORmula TRANslation. Developed by IBM in 1957. It is a SCIENTIC LANGUAGE. The versions are FORTRAN 66,77. COBOL : Common Business Oriented Language. It is developed by a group of computer professionals called Conference on Data Systems Language ( CODASYL) in 1959. Its primary domain is business, finance and admin. BASIC: Beginners All Purpose Symbolic Instruction Code. It is a first HLL which used on the personal computers. SNOBOL: StriNg Oriented and SymBOlic Language Developed in 1962 in Bell Labs C++, Java, C# : Object Oriented Languages Lisp Lisp: Means List Processing Language This is second oldest HLL than ForTran Lisp was originally created as a Practical mathematical notation for computer programs In 1956 John McCarthy first developed the basics behind lisp. In 1965 the primary dialect of LISP was created. In 1980 OOPS concepts are added. List of Interpreter are : Emacs, Omega, LispWorks MatLab It stands for Mathematics Laboratory. This is not Open Source. This is developed by MathWork Company. This lang. is basically used for Research Purpose. It has different tool box like Image Processing, Wireless Network, Neural Network. Octave (Gnu Octave) This open source. This is equivalent to MATLAB. All commands which work in MatLab can work in Octave. GNU Octave is a high-level interpreted language, primarily intended for numerical computations. It provides capabilities for the numerical solution of linear and nonlinear problems, and for performing other numerical experiments. It also provides extensive graphics capabilities for data visualization and manipulation. Octave is normally used through its interactive command line interface, but it can also be used to write non- interactive programs. The Octave language is quite similar to Matlab so that most programs are easily portable. What is ‘C’ ? C is programming language developed at AT&T’s Bell Laboratory of USA in 1972. It was written by Dennis Ritchie. C is popular because it is reliable, simple and easy to use. In Industry so many new languages coming and out in years but is till popular since 4-5 decades. Features of C Currently, the most commonly-used language for embedded systems “High-level assembly” Very portable: compilers exist for virtually every processor Easy-to-understand compilation Produces efficient code Features of C C is the most popular programming language, C has many advantages: Modularity: modularity is one of the important characteristics of C. We can split the C program into no. of modules instead of repeating the same logic statements (sequentially). It allows reusability of modules. Middle level language: as a middle level language C combines both the advantages of low level and high level languages. (arrays, pointers etc). General purpose programming language: C can be used to implement any kind of applications such as math’s oriented, graphics, business oriented applications. Portability: we can compile or execute C program in any operating system(unix, dos, windows). Powerful programming language: C is very efficient and powerful programming language, it is best used for data structures and designing system software. Basic Concepts of C Programming Language There are 3 types of Computer wares. 1. Human ware: The person, who can use the system, is called 'Human Ware ". He is also called as "User". 2. Hardware : The physical components (devices) of a system are called "Hardware". Eg. Monitor, CPU, Keyboard, Mouse etc. 3. Software : Def: Set of related programs is called “Software". Translators Assembler: It is translating software. It translates assembly code to binary and vice versa. Compiler / Interpreter: Both are translating soft wares. Those can translate high level language to binary language and vice versa. Compiler can process a whole file at a time and it provides .exe files. But, Interpreter can process a file line-by-line only. It does not provide .exe files. This is the main difference between them. Learning Steps in 'C' : 1. Character Set 2. Word 3. Instruction 4. Program 5. Software Character Set : Def: All allowable symbols in this language are called "Character set". The following characters are used in this language. Lower case letters : a b c … z Upper case letters : A B C….Z Digits : 0 1 2 3…9 Other characters : + - * ( ) & % $ # { } [ ]’ “ : ; etc. White space characters : blank, new line, tab space etc. Word: Def: Group of characters is called a 'Word'. There are 3 types of words in C. 1. Keyword 2. Variables and / or Identifiers 3. Constants Instructions: Def: Collection of words has returns a complete meaning and ends with a semicolon (;) is called an Instruction. Types of Instructions 1. Type declaration Instructions: Any variable is used in a program that must be declaring its data type before using it. syn: datatype var1, var2 , ...; Eg. int a; float data; Char grade; Types of Instructions 2. I/O Instructions: To read data from key board (std. input device) using a statement. That is called "Input instruction". To display the information on the monitor (std. output device) using a statement. That is called "Output Instruction". Syn: scanf ( ) ; : This is the standard input instruction in C. printf ( ) ; : This is the standard output Instruction in C. 3. Arithmetic instructions: Def: These instructions can perform Arithmetic calculations. Eg. c = a+b; gross = basic + hra +da; etc. 4. Control instructions: Def: To control the flow of execution of the program using certain statements are called "Control Instructions ". Eg. if statement, looping statements etc. Preprocessor directive #include <stdio.h> void main() Main function of program { printf("Hello, World! \n"); Function used for printing out data on screen } Escape Sequences Character \b Backspace \\ Backslash \f Form feed \‘ Single quotation mark \n Newline \“ Double quotation mark \r Return \? Question mark \t Horizontal tab \0 Null character \v Vertical tab Keywords in C Identifiers identify a variable, function, or any other user- defined item. An identifier starts with a letter A to Z, mohd a23b9 a to z, or An underscore '_' followed by zero or more letters, underscores, Digits (0 to 9) C does not allow punctuation characters such as @, $, and % within identifiers.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages66 Page
-
File Size-