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.

Slides:



Advertisements
Similar presentations
IT151: Introduction to Programming
Advertisements

Lecture 2 Introduction to C Programming
University of Palestine software engineering department Introduction to data structures Introduction to java application instructor: Tasneem Darwish.
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 2 Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
Introduction to C Programming
Introduction Kingdom of Saudi Arabia Shaqra University
COSC 120 Computer Programming
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
Introduction to C Programming
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.
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 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
C How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Week 1 Algorithmization and Programming Languages.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE 1 st semester H 1 King Saud University College of Applied studies and Community Service Csc 1101 By:
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.
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
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,
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
برمجه حاسبات 2 أ. بيان غزلان الفصل الدراسي هـ.
Chapter 1 Introduction 2nd Semester H
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE
Chapter 1: Introduction to computers and C++ Programming
Chapter 2 Introduction to C++ Programming
CSC201: Computer Programming
Introduction to C Language
Chapter 2 - Introduction to C Programming
Chapter 2, Part I Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
Java programming lecture one
Chapter 2 - Introduction to C Programming
Chapter 1: Introduction to Computers and Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Chapter 2 - Introduction to C Programming
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.
Programs written in C and C++ can run on many different computers
Chapter 2 - Introduction to C Programming
Computer Programming-1 CSC 111
Introduction to C Programming
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

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 programmer productivity, thereby reducing software-development costs—structured programming (in C).  A computer consists of various devices referred to as hardware  (e.g., the keyboard, screen, mouse, hard disks, memory, DVD drives and processing units).  Computing costs are dropping dramatically, owing to rapid developments in hardware and software technologies. Dr. Soha S. Zaghloul2Copyright © Pearson, Inc All Rights Reserved.

 Regardless of differences in physical appearance, computers can be envisioned as divided into various logical units or sections (Fig. 1.2). Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul3Copyright © Pearson, Inc All Rights Reserved.

Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul4Copyright © Pearson, Inc All Rights Reserved. input devices : Allows people to supply information to computers

Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul5Copyright © Pearson, Inc All Rights Reserved. Memory :„ Stores information being processed by the CPU Output devices: Allows people to receive information from computers

Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul6Copyright © Pearson, Inc All Rights Reserved. Arithmetic Logic Unit : It performs mathematical operations on binary numbers. The ALU uses to operands and code that tells it which operations to perform for input data. the ALU is divided into an AU and LU. The AU performs the arithmetic operations, and the LU performs the logical operations. CPU : the brain of the computer, The computer CPU is responsible for handling all instructions it receives from hardware and software running on the computer.

Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul7Copyright © Pearson, Inc All Rights Reserved. Secondary storage Unit : external memory that holds data until it is deleted or overwritten. Secondary storage is about two orders of magnitude cheaper than primary storage. hard drives (a prime example of secondary storage) are the go-to solution for nearly all data kept on today's computers.

 As you’ll learn later, C programs consist of pieces called functions.  You can program all the functions you need to form a C program, but most C programmers take advantage of the rich collection of existing functions called the C Standard Library.  When programming in C you’ll typically use the following building blocks:  C Standard Library functions  Functions you create yourself  Functions other people (whom you trust) have created and made available to you Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul8Copyright © Pearson, Inc All Rights Reserved.

 The first step consists of editing a file with an editor program.  You type a C program with the editor, make corrections if necessary, then store the program on a secondary storage device such as a hard disk.  C program file names should end with the.c extension. Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul9Copyright © Pearson, Inc All Rights Reserved.

 The C preprocessor obeys special commands called preprocessor directives, which indicate that certain manipulations are to be performed on the program before compilation.  These manipulations usually consist of including other files (#include ) in the file to be compiled and performing various text replacements. Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul10Copyright © Pearson, Inc All Rights Reserved.

 Then, you give the command to compile the program.  The compiler translates the C program into machine language-code.  A syntax error occurs when the compiler cannot recognize a statement because it violates the rules of the language.  Syntax errors are also called compilation. Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul11Copyright © Pearson, Inc All Rights Reserved.

 C programs typically contain references to functions defined elsewhere, such as in the standard libraries or in the private libraries of groups of programmers working on a particular project.  The object code produced by the C compiler typically contains “holes” due to these missing parts.  A linker links the object code with the code for the missing functions to produce an executable file (with no missing pieces).  If the program compiles and links correctly, an executable file is produced. Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul12Copyright © Pearson, Inc All Rights Reserved.

 Before a program can be executed, the program must first be placed in memory.  This is done by the loader, which takes the executable image from disk and transfers it to memory.  Additional components from shared libraries that support the program are also loaded. Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul13Copyright © Pearson, Inc All Rights Reserved.

 Finally, the computer, under the control of its CPU, executes the program one instruction at a time.  Run-time errors may occur while program execution.  For example, a program might attempt to divide by zero (an illegal operation on computers just as in arithmetic).  This causes the program to terminate immediately giving an error message.  Non fatal errors may let the program terminate giving incorrect results. Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul14Copyright © Pearson, Inc All Rights Reserved.

Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul15Copyright © Pearson, Inc All Rights Reserved.

Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul16Copyright © Pearson, Inc All Rights Reserved.

Copyright © Pearson, Inc All Rights Reserved. Dr. Soha S. Zaghloul17Copyright © Pearson, Inc All Rights Reserved.

 We begin by considering a simple C program.  Our first example prints a line of text (Fig. 2.1). © by Pearson Education, Inc. All Rights Reserved. Dr. Soha S. Zaghloul18Copyright © Pearson, Inc All Rights Reserved.

© by Pearson Education, Inc. All Rights Reserved. Dr. Soha S. Zaghloul19Copyright © Pearson, Inc All Rights Reserved. comments Directive to the C preprocessor Main function block statement

 Lines 1 and 2 // Fig. 2.1: fig02_01.c A first program in C  begin with //, indicating that these two lines are comments.  You insert comments to document programs and improve program readability.  Comments do not cause the computer to perform any action when the program is run.  Comments are ignored by the C compiler and do not cause any machine-language object code to be generated.  Comments also help other people read and understand your program. © by Pearson Education, Inc. All Rights Reserved. C OMMENTS … Dr. Soha S. Zaghloul20Copyright © Pearson, Inc All Rights Reserved.

 You can also use /*…*/ multi-line comments in which everything from /* on the first line to */ at the end of the line is a comment.  We prefer // comments because they’re shorter and they eliminate the common programming errors that occur with /* … */ comments, especially when the closing */ is omitted. © by Pearson Education, Inc. All Rights Reserved. C OMMENTS … Dr. Soha S. Zaghloul21Copyright © Pearson, Inc All Rights Reserved.

#include Preprocessor Directive  Line 3 #include  is a Directive to the C preprocessor.  Lines beginning with # are processed by the preprocessor before compilation.  Line 3 tells the preprocessor to include the contents of the standard input/output header ( ) in the program.  This header contains information used by the compiler when compiling calls to standard input/output library functions such as printf. © by Pearson Education, Inc. All Rights Reserved. P REPROCESSOR D IRECTIVE … Dr. Soha S. Zaghloul22Copyright © Pearson, Inc All Rights Reserved.

Blank Lines and White Space  Line 4 is simply a blank line. You use blank lines, space characters and tab characters (i.e., “tabs”) to make programs easier to read.  Together, these characters are known as white space. White-space characters are normally ignored by the compiler. © by Pearson Education, Inc. All Rights Reserved. W HITE S PACE C HARACTERS … Dr. Soha S. Zaghloul23Copyright © Pearson, Inc All Rights Reserved.

The main Function  Line 6 int main( void )  is a part of every C program.  The parentheses after main indicate that main is a program building block called a function. © by Pearson Education, Inc. All Rights Reserved. T HE M AIN F UNCTION … Dr. Soha S. Zaghloul24Copyright © Pearson, Inc All Rights Reserved.

 C programs contain one or more functions, one of which must be main.  Every program in C begins executing at the function main.  The keyword int to the left of main indicates that main “returns” an integer (whole number) value.  We’ll explain what it means for a function to “return a value” when we demonstrate how to create your own functions.  For now, simply include the keyword int to the left of main in each of your programs.  Functions also can receive information when they’re called upon to execute.  The void in parentheses here means that main does not receive any information. © by Pearson Education, Inc. All Rights Reserved. T HE M AIN F UNCTION … Dr. Soha S. Zaghloul25Copyright © Pearson, Inc All Rights Reserved.

© by Pearson Education, Inc. All Rights Reserved. T HE M AIN F UNCTION … Dr. Soha S. Zaghloul26Copyright © Pearson, Inc All Rights Reserved.

 A left brace, {, begins the body of every function (line 7).  A corresponding right brace ends each function (line 11).  This pair of braces and the portion of the program between the braces is called a block. © by Pearson Education, Inc. All Rights Reserved. B LOCKS … Dr. Soha S. Zaghloul27Copyright © Pearson, Inc All Rights Reserved.

An Output Statement  Line 8 printf( "Welcome to C!\n" );  instructs the computer to perform an action, namely to print on the screen the string of characters marked by the quotation marks.  The entire line, including the printf function (the “f” stands for “formatted”), its argument within the parentheses and the semicolon ( ; ), is called a statement.  Every statement must end with a semicolon (also known as the statement terminator).  When the preceding printf statement is executed, it prints the message Welcome to C! on the screen.  The characters normally print exactly as they appear between the double quotes in the printf statement. © by Pearson Education, Inc. All Rights Reserved. O UTPUT S TATEMENT … Dr. Soha S. Zaghloul28Copyright © Pearson, Inc All Rights Reserved.

 The right brace, }, (line 9) indicates that the end of main has been reached. © by Pearson Education, Inc. All Rights Reserved. E ND OF M AIN … Dr. Soha S. Zaghloul29Copyright © Pearson, Inc All Rights Reserved.

© by Pearson Education, Inc. All Rights Reserved. Dr. Soha S. Zaghloul30Copyright © Pearson, Inc All Rights Reserved.

© by Pearson Education, Inc. All Rights Reserved. Dr. Soha S. Zaghloul31Copyright © Pearson, Inc All Rights Reserved.

© by Pearson Education, Inc. All Rights Reserved. Dr. Soha S. Zaghloul32Copyright © Pearson, Inc All Rights Reserved.