Presentation is loading. Please wait.

Presentation is loading. Please wait.

Choice of Programming Language

Similar presentations


Presentation on theme: "Choice of Programming Language"— Presentation transcript:

1 Choice of Programming Language
All the information is stored in the memory must be in the form of binary. As such any program to be executed by the CPU must be in the form of 0 and 1. Low-Level Programming Languages Machine Language All the instructions, commands, expressions and data are in the form of 0 and 1. Pros: CPU can understand the program and can execute (run) the program. Cons: Are extremely difficult to write or read programs.

2 ASSEMBLY LANGUAGE Assembly Language
All the instructions are in the form of short and easily understood codes such as MOVE, ADD, SUB, JMP, etc. Data can be in Binary/Dec/Oct/ Hex. Pros: Much easier to work with than machine language. Cons: Still not easy to read or write. Example: TO ADD 5 TO 6 MOVE #5, R1 MOVE #6, R2 ADD R1, R2, R3 Needs a translator program which converts the assembly code to 0 and 1. Since after all CPU can only work with 0 and 1s. This program is known as Compiler or, in the case of Assembly Language, Assembler. Note:

3 High Level Languages High-Level Programming Languages C Fortran Pascal
Turing Example: TO ADD 5 TO 6 sum = 5 + 6; These programming languages are easy to read/write since the instructions are English like sentences. we still need to compile & to link our program. Note:

4 Solving Problems Here are the steps required to solve a problem with a computer program: 1. Define the problem 2. Analyse the problem. 3. Design a solution. 4. Implement the solution. 5. Test the program. 6. Update and maintain the program.

5 Why teach C? C is small (only 32 keywords). C is common (lots of C code about). C is stable (the language doesn’t change much). C is quick running. C is the basis for many other languages (Java, C++, awk, Perl). It may not feel like it but C is one of the easiest languages to learn.

6 C : Introduction The language is called “C” because its direct ancestor was called “B”. C was created around 1972 by Kernighan and Ritchie.

7 Programming Facilities
Generally there needs to be a number software applications that facilitate production of a program including: Editors, Complier, Library, Linker Programming Environment or Integrated Development Environment (IDE) An environment that has all the different programming tools needed for a particular programming language

8 Note: Collection of ‘C’ programming tools
‘C’ Environment Collection of ‘C’ programming tools Borland ‘C++’, Quincy All environments are operating under some OS. Above mentioned IDEs are available under the WINDOWS. Note:

9 Some programmer jargon
Some words that will be used a lot: Source code: The stuff you type into the computer. The program you are writing. Compile (build): Taking source code and making a program that the computer can understand. Executable: The compiled program that the computer can run. Library: Added functions for C programming which are bolted on to do certain tasks. Header file: Files ending in .h which are included at the start of source code.

10 Data Types in ‘C’ Major data types Numbers: any numerical value.
Characters: any item from set of characters used by C. Strings: a combination of characters. Void: any expression that does not have any value 10 10

11 Numbers in ‘C’ Two general categories: Integers Floats
Unsigned – all positive integers Signed – positive and negative integers Floats 11 11

12 Constants in C There are 3 basic types of constants in C.
An integer constant is an integer-valued number.We will concern here solely with decimal constants like 0, 1, 743, 5280, or -764. A floating point constant is a base-10 number than contains either a decimal point or an exponent or both like 0., 1., 0.2, 50.0, 12.3, , 2E-8 or 0.006e-3. A character constant is a single character enclosed in apostrophes like 'a', 'x', '9', or '?'.

13 Preprocessor directives
Preprocessor: A system program that modifies the C program prior to compilation. Preprocessor directive: An instruction to the preprocessor. Begins with #. Library: A collection of functions, symbols and values. 2 kinds of preprocessor directives: includes and defines.

14 Preprocessor directives
#include <stdio.h>: stdio.h, which stands for "standard input/output header", is the header in the C standard library that contains macro definitions, constants, and declarations of functions and types used for various standard input and output operations. The #include <stdio.h> directive must be included on top of every C program. #define PI : this is a constant macro definition. It associates a name to a value for the duration of the program In this case it associates the symbol PI to the value It is an optional directive.

15 Comments Comments are lines of code that are ignored by the compiler. They are placed for the programmer's benefit. /* this is a comment */ /* this is another comment, it can be spread over multiple lines */

16 Instructions Instructions in C are terminated by a semi-colon (;)
Line changes and tabs are not important to the C compiler. a=3; b=4; c=5; are the same as a=3; b=4; c=5;

17 Skeleton of a program #include <stdio.h> /* optional additional includes */ /* optional constant macros */ int main (void) { /* optional declarative statements */ /* one or more executable statements */ return (0); }

18 /* PROGRAM # 1 */ #include <stdio.h>
/* This is my first C program. */ /* It’ll print a message to the display. */ int main (void ){ printf(“Welcome to the C programming language course!\n”); printf("This is our very first C program.\n"); printf(“We wish you a very pleasant experience with C.”); return (0); } 18 18

19 This is what we see after execution:
1st line: Welcome to the C programming language course! 2nd line: This is our very first C program. 3rd line: We wish you a very pleasant experience with C. 19 19

20 Conversion Decimal number to signed integer(32-bit)(2-compliment for negative numbers) Binary to decimal

21 Choose the biased exponent
(32-bits)(floating point numbers IEEE-754) Binary to decimal(32-bit-floating point IEEE-754)


Download ppt "Choice of Programming Language"

Similar presentations


Ads by Google