Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction of Programming Languages

Similar presentations


Presentation on theme: "Introduction of Programming Languages"— Presentation transcript:

1 Introduction of Programming Languages

2 PROGRAMMING LANGUAGE A programming language is a notation for writing programs, which are specifications of a computation or algorithm A programming language is a set of rules that provides a way of telling a computer what operations to perform A programming language is a set of rules for communicating an algorithm Medium of communication between computer and the user containing words, symbols and syntax rules Each language has its own vocabulary and rules.

3 FIVE GENERATIONS OF PROGRAMMING LANGUAGES
Machine Language (1st Generation Language – 1945) Assembly Language(2nd Generation Language – 1950s) High Level Language (3rd Generation Language – 1960s) Very High Level Language (4th Generation Language – 1970s) Natural Language (5th Generation Language – 1980)

4 MACHINE LANGUAGE (1ST GENERATION LANGUAGE – 1945)
The set of instruction codes, in binary, which can be directly understood by the CPU without translating the program. An instruction has two parts: Op-Code: First part of instruction which tells the computer what function to perform. Operand: Second part of instruction, tells the computer where to find or store data or instructions that are to be manipulated. The lowest-level, programming language. Machine Dependent. Difficult to program. Error Prone. Difficult to modify.

5 ASSEMBLY LANGUAGE(2ND GENERATION LANGUAGE – 1950S)
A low-level language. Allows the programmer to use abbreviations or words instead of binary numbers, known as mnemonics. A program called an assembler transforms assembly language into machine code. Readability is more than machine language. Easy to understand and use. Easy to locate and correct errors. Easier to modify. Limitations: Machine dependent. Knowledge of hardware. Machine level coding.

6 HIGH LEVEL LANGUAGE (3RD GENERATION LANGUAGE – 1960S)
Also known as Procedure/Problem Oriented Language. Machine independent. Easier to learn and use than previous languages. Requires less time to write the code. Easier to maintain. Provides better documentation. Fewer Errors. Lower program preparation cost. Lack of flexibility.

7 ORG 100 /Origin of program is location 100 LDA A /Load operand from location A ADD B /Add operation form location B STA C /Store sum in location C HLT /Halt computer A, DEC 83 /Decimal operand B, DEC –2 C, DEC 0 /Sum stored in location C END int a, b, c; a = 83; b = -2; c = a + b; Instruction Code Binary Instruction Comments LDA 104 Load first operand into AC ADD 105 Add second operand to AC STA 106 Store sum in location 106 HLT Halt computer operand 83 decimal -2 decimal Store sum here

8 HIGH LEVEL LANGUAGE (3RD GENERATION LANGUAGE – 1960S)
FORTRAN Formula Translation Language COBOL Common Business Oriented Language ALGOL Algorithmic Language RPG Report Program Generator APL A Programming Language BASIC Beginners All Purpose Symbolic Instruction Code PL/I Programming Language I PASCAL Named after Blaise Pascal, a French Philosopher Ada Named after Lady Lovelace Ada C General Purpose Programming Language C++ Object Oriented Programming Language JAVA Object Oriented Programming Language

9 EXTRACT ALL CUSTOMERS WHERE "PREVIOUS PURCHASES" TOTAL MORE THAN $1000
VERY HIGH LEVEL LANGUAGE (4TH GENERATION LANGUAGE – 1970S) Also known as 4GL or non-procedural language. Machine independent. Easier to learn and use. Easier to maintain. The tools are: DBMS Report Generators Query Languages Application Generators. EXTRACT ALL CUSTOMERS WHERE "PREVIOUS PURCHASES" TOTAL MORE THAN $1000

10 5TH GENERATION LANGUAGE – 1980
Fifth-generation languages are designed to make the computer solve a given problem without the programmer. Natural Languages Programming Languages: that use human language to give people more natural connection with computers with 4GLs. Using AI (Artificial Intelligence), the attempt to make computers which will have human like qualities such as learning, reasoning, communicating, seeing and hearing etc. Prolog, OPS5 and Mercury are the best known 5th generation languages. Fifth - Generation language is Programming that uses a visual or graphical development interface to create source language that is usually compiled with a 3GL or 4GL language compiler.

11 Introduction to C

12 C is often called a "Middle Level" programming language.
Most high-level languages provides everything the programmer might want to do already built into the language. A low level language (e.g. assembler) provides nothing other than access to the machines basic instruction set. A middle level language, such as C, probably doesn't supply all the constructs found in high-languages - but it provides you with all the building blocks that you will need to produce the results you want!

13 Why C The portability of the compiler; The standard library concept;
A powerful and varied repertoire of operators; An elegant syntax; Ready access to the hardware when needed; Ease with which applications can be optimised by hand-coding isolated procedures

14 Uses of C Operating Systems Language Compilers Assemblers Text Editors
Print Spoolers Network Drivers Modern Programs Data Bases Language Interpreters Utilities

15 Special Characters in C Programming
C's Character Set Alphabets Digits Special Characters Special Characters in C Programming , < > . _ ( ) ; $ : % [ ] # ? ' & { } " ^ ! * / | - \ ~ +

16 The only function that has to be present is the function called main.
pre-processor directives global declarations main() { local variables to function main ; statements associated with function main ; } f1() local variables to function 1 ; statements associated with function 1 ; f2() local variables to function f2 ; statements associated with function 2 ; . etc All C programs will consist of at least one function, but it is usual to write a C program that comprises several functions. The only function that has to be present is the function called main.  The general form of a C program is as follows

17 Pre-processor Directives
All pre-processor directives begin with a # and the must start in the first column. The commonest directive to all C programs is: #include<stdio.h> stdio.h is the C's standard libraries which deals with standard inputting and outputting of data #include "stdio.h" The double quotes indicate that the current working directory should be searched for the required header file. This will be true when you write your own header files but the standard header files should always have the angle brackets around them.

18 C Keywords Keywords are predefined, reserved words used in programming that have special meanings to the compiler. Keywords are part of the syntax and they cannot be used as an identifier. For example: Keywords in C Language auto double int struct break else long switch case enum register  typedef char extern return union continue for signed void do if static  while default goto sizeof volatile const float short unsigned

19 double accountBalance;
C Identifiers Identifier refers to name given to entities such as variables, functions, structures etc. Identifier must be unique. They are created to give unique name to a entity to identify it during the execution of the program. For example: int money; double accountBalance; Here, money and accountBalance are identifiers. Identifier names must be different from keywords. You cannot use int as an identifier because int is a keyword. Rules for writing an identifier A valid identifier can have letters (both uppercase and lowercase letters), digits and underscores. The first letter of an identifier should be either a letter or an underscore. However, it is discouraged to start an identifier name with an underscore. There is no rule on length of an identifier. However, the first 31 characters of identifiers are discriminated by the compiler.

20 Variable Variable (computer science), a symbolic name associated with a value and whose associated value may be changed Constant Constant (computer programming), a value that, unlike a variable, cannot be reassociated with a different value Data Types Data types are declarations for memory locations or variables that determine the characteristics of the data that may be stored and the methods (operations) of processing that are permitted involving them.

21 They are arithmetic types and are further classified into:
Basic Data Types They are arithmetic types and are further classified into: (a) integer types and (b) floating-point types. Type Storage size char 1 byte unsigned char signed char int 2 or 4 bytes unsigned int short 2 bytes unsigned short long 4 bytes or 8 bytes unsigned long

22 Format Specifier Format specifiers defines the type of data to be printed on standard output. Whether to print formatted output or to take formatted input we need format specifiers. Type Format Specifier char %c unsigned char signed char int %d or %i unsigned int %u short %hd or %hi unsigned short %hu long %li or %ld unsigned long %lu

23 Integer Data Types To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes. #include <stdio.h> void main() { printf("int %d \n",sizeof(int)); printf("char %d \n",sizeof(char)); printf("unsigned int %d \n",sizeof(unsigned int)); printf("signed int %d \n",sizeof(signed int)); printf("long %d \n",sizeof(long)); }

24 Integer Data Types Minimum and Maximum Values
#include <stdio.h> #include<limits.h> void main() { long a; printf("int MIN %d and Max is %d \n",INT_MIN, INT_MAX); printf("char MIN %d and Max is %d \n",CHAR_MIN,CHAR_MAX); printf("long Min %ld and Max is %ld \n",LONG_MIN,LONG_MAX); }

25

26 Character Data Type #include <stdio.h> void main() { char ch=‘A’; printf(“%c \n”,ch); pritnf(“ASCII CODE of ch is %d”,ch); } #include <stdio.h> void main() { char ch=97; printf(“%c \n”,ch); pritnf(“ASCII CODE of ch is %d”,ch); }

27 Floating-Point Types Type Storage size Format Specifier float 4 byte
double 8 byte %f, %E for Scientific notation long double 16 byte %Lf, %LE #include <stdio.h> #include<float.h> int main() { printf("Float Min %E Max is %E and Precision is %d\n",FLT_MIN,FLT_MAX,FLT_DIG); printf("double Min %E Max is %E and Precision is %d\n",DBL_MIN,DBL_MAX,DBL_DIG); printf("Long double Min %LE Max is %LE and Precision is %d\n",LDBL_MIN,LDBL_MAX,LDBL_DIG); return 0; }

28 Format Specifiers with printf
%d (print as a decimal integer) %6d (print as a decimal integer with a width of at least 6 wide) %06d (print as a decimal integer with a width of at least 6 wide filled with 0 rather than space) Hexadecimal: %x Octal: %o %f (print as a floating point) %4f (print as a floating point with a width of at least 4 wide) %.4f (print as a floating point with a precision of four characters after the decimal point) %3.2f (print as a floating point at least 3 wide and a precision of 2)

29 String Format Specifiers with printf
statement prints the string %15s statement prints the string, but print 15 characters. If the string is smaller the “empty” positions will be filled with “whitespace.” %.10s statement prints the string, but print only 10 characters of the string. In case the string is shorter than 10, the whole string is printed. %-10s statement prints the string, but prints at least 10 characters. If the string is smaller “whitespace” is added at the end. %15.10s statement prints the string, but print 15 characters. If the string is smaller the “empty” positions will be filled with “whitespace.” But it will only print a maximum of 10 characters. %-15.10s statement prints the string, but it does the exact same thing as the previous statement, accept the “whitespace” is added at the end.


Download ppt "Introduction of Programming Languages"

Similar presentations


Ads by Google