CHAPTER 1: INTORDUCTION TO C LANGUAGE

Slides:



Advertisements
Similar presentations
Programming In C++ Spring Semester 2013 Programming In C++, Lecture 1
Advertisements

ICS103 Programming in C Lecture 1: Overview of Computers & Programming
INTRODUCTION T.Najah Al_Subaie Kingdom of Saudi Arabia Prince Norah bint Abdul Rahman University College of Computer Since and Information System CS240.
COSC 120 Computer Programming
Three types of computer languages
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Chapter 1 Introduction to C Programming. 1.1 INTRODUCTION This book is about problem solving with the use of computers and the C programming language.
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
C programming Language and Data Structure For DIT Students.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Programming In C++ Spring Semester 2013 Programming In C++, Lecture 1.
Principles of Programming Chapter 1: Introduction  In this chapter you will learn about:  Overview of Computer Component  Overview of Programming 
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
“C” Programming Language What is language ? Language is medium of communication. If two persons want to communicate with each other, they have to use.
CSC141 Introduction to Computer Programming
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
Programming With C.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
Sharda University P. K. Mishra (Asst.Prof) Department of Computer Science & Technology Subject Name: Programming Using C Sub Code: CSE-106 Programming.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
INTRODUCTION Kingdom of Saudi Arabia Princess Nora bint Abdul Rahman University College of Computer Since and Information System CS240.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
Introduction to Computer Application (IC) MH Room 517 Time : 7:00-9:30pm.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
Chapter 2 part #1 C++ Program Structure
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
Agenda Computer Languages How to Write a Simple C Program
Principles of Programming Chapter 1: Introduction  In this chapter you will learn about:  Overview of Computer Component  Overview of Programming 
Preston University, Islamabad Campus
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Software Engineering Algorithms, Compilers, & Lifecycle.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
Introduction to C Topics Compilation Using the gcc Compiler
Chapter 1 Introduction 2nd Semester H
UMBC CMSC 104 – Section 01, Fall 2016
Chapter 1: Introduction to computers and C++ Programming
CSC201: Computer Programming
Introduction to C Language
C Programming Hardik H. Maheta.
Chapter 2, Part I Introduction to C Programming
Instructor: Chien-Ho Ko
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Introduction to C Topics Compilation Using the gcc Compiler
Choice of Programming Language
Welcome In The World Of ‘C’.  TEXT BOOK: Programming in ANSI ‘C By: E Balagurusamy. TMH  Reference Books: 1) The ‘C Programming Language By: Kernighan.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Programming Fundamentals Lecture #3 Overview of Computer Programming
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
C programming Language
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

CHAPTER 1: INTORDUCTION TO C LANGUAGE Programming languages: A programming language is a computer language programmers use to develop applications or other set of instructions for a computer to execute. A programming language is a formal language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely.

ASSEMBLY LANGUAGE MACHINE LANGUAGE

CATEGORIES OF PROGRAMMING LANGUAGES A HIGH LEVEL LANGUAGE is a language for programming computers which does not require detailed knowledge of a specific computer. High-level languages do not have to be written for a particular computer, but must be compiled for the computer they will work with. High-level languages are closer to human language than low-level languages, and include statements like GOTO or FOR which are regular words. On the other hand, a LOW LEVEL LANGUAGE is a computer programming language that is close to machine language. MACHINE LANGUAGE is at the lowest level, because it is the actual binary code of 1s and 0s that the computer understands. ASSEMBLY LANGUAGES are low- level languages which are translated into machine code by an assembler. Each assembly language instruction corresponds to one machine language instruction, but assembly language is easier notation for the programmer to use than machine code.

High Level Language Assembly Language Machine Language

SOURCE CODE OBJECT CODE HIGH LEVEL LANGUAGE PROGRAM MACHINE LANGUAGE PROGRAM COMPILER OR INTERPRETER ASSEMBLY LANGUAGE PROGRAM ASSEMBLER

Compiler: It is a program which translates a high level language program into a machine language program. A compiler goes through the entire program and then translates the entire program into machine codes. Interpreter: An interpreter is a program which translates statements of a program into machine code. It translates only one statement of the program at a time. It reads only one statement of program, translates it & executes it. Then it reads the next statement of the program again translates it & executes it. In this way it proceeds further till all the statements are translated and executed. On the other hand, a compiler goes through the entire program and then translates the entire program into machine codes. A compiler is 5 to 25 times faster than an interpreter. Assembler: A computer will not understand any program written in a language, other than its machine language. The programs written in other languages must be translated into the machine language. Such translation is performed with the help of software. A program which translates an assembly language program into a machine language program is called an assembler.

High level Languages: Very early in the development of computers attempts were made to make programming easier by reducing the amount of knowledge of the internal workings of the computer that was needed to write programs. If programs could be presented in a language that was more familiar to the person solving the problem, then fewer mistakes would be made.  High-level programming languages allow the specification of a problem solution in terms closer to those used by human beings. These languages were designed to make programming far easier, less error-prone and to remove the programmer from having to know the details of the internal structure of a particular computer. These high-level languages were much closer to human language. Many high level languages have appeared (and many have also disappeared!). 

COBOL Business applications FORTRAN Engineering & Scientific Applications PASCAL General use and as a teaching tool C & C++ General Purpose - currently most popular PROLOG Artificial Intelligence JAVA General Purpose - gaining popularity rapidly COBOL COmmon Business-Oriented Language FORTRAN  Formula Translation BASIC Beginner's All-purpose Symbolic Instruction Code

Become A Better Programmer Learn C Programming Language

A Brief History of C C is a general-purpose language. The C programming language was devised in the early 1970s by Dennis M. Ritchie at Bell Labs, to implement the UNIX operating system. Characteristics of C Language C is an All purpose programming language. It is equally suitable for generating high level application and low level application. Sometimes it is also called the mid-level language. C language encourages the users to write their own library function so that they can extend the features of the language. C program can be executed on any type of computers. The program written in C language can be converted into machine language more efficiently. Computer games can be generated in C language which is accomplished through the usage of sound graphics. C is close to hardware. Both low and high level programming can be done in C language. It is a highly structured language.

A C program basically has the following form: Preprocessor Commands Functions Variables Statements & Expressions Comments Braces and semicolon To print “I Love Pakistan” on screen following simple C program can be used: # include <stdio.h> void main(void) { printf(“I Love Pakistan”); } Preprocessor Commands # sign indicates that this is an instruction for the compiler <stdio.h> stands for standard input-output header printf( ) is a library function used to print. The left brace { indicates the start of the body of the any function. The right brace } indicates the end of the body of the any function. A statement in C is terminated with a semicolon. : Preprocessor Commands: These commands tells the compiler to do preprocessing before doing actual compilation. Like #include <stdio.h> is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation.

A C program can basically has the following form: Preprocessor Commands Functions Variables Statements & Expressions Comments Braces and semicolon To print “I Love Pakistan” on screen following simple C program can be used: # include <stdio.h> void main(void) { printf(“I Love Pakistan”); }

# sign indicates that this is an instruction for the compiler <stdio.h> stands for standard input-output header printf( ) is a library function used to print. The left brace { indicates the start of the body of the any function. The right brace } indicates the end of the body of the any function. A statement in C is terminated with a semicolon: Preprocessor Commands: These commands tells the compiler to do preprocessing before doing actual compilation. Like #include <stdio.h> is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation.

Note the followings C is a case sensitive programming language. It means in C printf and Printf will have different meanings. C has a free-form line structure. End of each C statement must be marked with a semicolon. Multiple statements can be one the same line. Statements can continue over multiple lines.

What is a C Program? A collection of functions which when compiled, assembled, linked, loaded, and executed performs some task.                                        

Compile: Translate a program from source code to assembly code.   Assemble: Translate a program from assembly code to object code (sometimes these two steps are combined and called compiling).   Link: Pull together all of the functions needed for the program (both user defined objects and system libraries) and arrange that locations of functions and variables are known. This step creates the executable program.   Load: Move the executable program into computer memory. Execute: Run the program, that means now the computer is going to act upon the instructions given in the program.

C Program Compilation Creating, Editing, Saving, Compiling, Debugging, Linking, Executing Creating C Program Editing C Program Saving C Program You can write, edit and save a C program in any text editor program. But Turbo C provides a complete IDE for this purpose. You can easily write, edit and save C program in TC editor. The process of writing a new C program by following the rules of C language is called creating a C program. To write a new C program, load the TC editor and type the source code of program. You can also make changes during writing new programs as well as in the exiting C program. Therefore, the process of writing, changing and revising the source code is called editing program. After writing or editing the source program, you should save it on the disk as text file with an extension " .c ". This process is called saving the program.

The Edit-Compile-Link-Execute Process: Developing a program in a compiled language such as C requires at least four steps: Editing (Or Writing) The Program Compiling It Linking It Executing It Editing: You write a computer program with words and symbols that are understandable to human beings. This is the editing part of the development cycle. You type the program directly into a window on the screen and save the resulting text as a separate file. This is often referred to as the source file . The custom is that the text of a C program is stored in a file with the extension .c for C programming language. Compiling: You cannot directly execute the source file. To run on any computer system, the source file must be translated into binary numbers understandable to the computer's Central Processing Unit. This process produces an intermediate object file - with the extension .obj, the .obj stands for Object.

Linking: The first question that comes to most peoples minds is Why is linking necessary? The main reason is that many compiled languages come with library routines which can be added to your program. Theses routines are written by the manufacturer of the compiler to perform a variety of tasks, from input/output to complicated mathematical functions. In the case of C the standard input and output functions are contained in a library (stdio.h) so even the most basic program will require a library function. After linking the file extension is .exe which are executable files. Executable files: Thus the text editor produces .c source files, which go to the compiler, which produces .obj object files, which go to the linker, which produces .exe executable file. You can then run .exe files as you can other applications, simply by typing their names at the DOS prompt or run using windows menu.

Structure of C Programs C's character set C's keywords the general structure of a C program that all C statement must end in a ; that C is a free format language all C programs use header files that contain standard library functions. Before writing any kind of program, one should have the concept of Flowcharts, which is the graphical representation of program.

Example: Write a C program to find the factorial of any number n.

Write a C program to find the factorial of any number n. # include <stdio.h> # include <conio.h> void main(void) {   int n, j,fact;   printf(“\nEnter a number: ");   scanf("%d", &n); fact=1;   for(j=1; j<=n; j=j+1)       fact=fact*j;   printf(“\nThe Factorial of %d is %d", n, fact);   return 0; }