CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 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++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
Introduction to C Programming
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Introduction to C Programming
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Computer Programming 1 Lecture-2 Instructor: Nasir Khan
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Ping Zhang 10/08/2010.  You can get data from the user (input) and display information to the user (output).  However, you must include the library.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
Introduction to Computer Programming in c
© 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.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Computer Programming Politehnica International- Computer Engineering Lecture Slides.
Introduction to Computer Programming in c
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
Overview of C. C—a high-level programming language developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories. We will discuss: –the elements of a.
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Program Development Cycle 1.Edit program 2.Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied,
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
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.
Chapter 1.2 Introduction to C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
User-Written Functions
Chapter 1.2 Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
ICS103 Programming in C Lecture 3: Introduction to C (2)
Chapter 2 - Introduction to C Programming
Chapter 7 - JavaScript: Introduction to Scripting
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Royal University of Phnom Penh Department of Computer Science
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Introduction to C Programming
Chapter 7 - JavaScript: Introduction to Scripting
Presentation transcript:

CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR

Compiling and Running Your First Program Outline: First C program Second program Displaying multiple lines of text Displaying the Values of Variables Displaying multiple values Using comments in a program 2

First C program #include int main (void) { printf ("Programming is fun.\n"); return 0; } uses standard library input and output functions (printf) the program begin of program end of program statements main: a special name that indicates where the program must begin execution. It is a special function. first statement: calls a routine named printf, with argument the string of characters “Programming is fun \n” last statement: finishes execution of main and returns to the system a status value of 0 (conventional value for OK) 3

Second program 4 #include int main (void) { printf ("Programming is fun.\n"); printf ("And programming in C is even more fun.\n"); return 0; }

Displaying multiple lines of text 5 #include int main (void) { printf ("Testing...\n..1\n...2\n....3\n"); return 0; } Output: Testing It is not necessary to make a separate call to printf for each line of output !

6 Programs can use symbolic names for storing computation data and results. Variable: a symbolic name for a memory location programmer doesn’t have to worry about specifying (or even knowing) the value of the location’s address. In C, variables have to be declared before they are used Displaying the Values of Variables

7 #include int main (void) { int sum; sum = ; printf ("The sum of 50 and 25 is %i\n", sum); return 0; } Variable sum declared of type int Variable sum assigned expression Value of variable sum is printed in place of %i The printf routine call has now 2 arguments: A string containing also a format specifier (%i), that holds place for an integer value to be inserted here and variable sum.

Displaying multiple values 8 #include int main (void) { int value1, value2, sum; value1 = 50; value2 = 25; sum = value1 + value2; printf ("The sum of %i and %i is %i\n",value1, value2, sum); return 0; } The format string must contain as many placeholders as expressions to be printed.

Using comments in a program 9 Comment statements are used in a program to document it and to enhance its readability. Useful for human readers of the program – compiler ignores comments Ways to insert comments in C: -When comments span several lines: start marked with /*, end marked with */ -Comments at the end of a line: start marked with //

Using comments in a program 10 /* This program adds two integer values and displays the results */ #include int main (void) { // Declare variables int value1, value2, sum; // Assign values and calculate their sum value1 = 50; value2 = 25; sum = value1 + value2; // Display the result printf ("The sum of %i and %i is %i\n",value1, value2, sum); return 0; }