CC112 Structured Programming Lecture 2 1 Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Advertisements

Computer Programming w/ Eng. Applications
Lecture 2 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.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
Computer Science Department FTSM Variables and Constants Knowledge: Understand the concept of storage location representation as identifiers Skill: Identify.
Dale/Weems/Headington
1 CS 201 Introduction to C (1) Debzani Deb. 2 Outline Overview of C General form of a C program C Language Elements.
Software Development Method & C Language Elements H&K Chapter 1-2
Introduction to Computing Lecture 01: Introduction to C Introduction to Computing Lecture 01: Introduction to C Assist.Prof.Dr. Nükhet ÖZBEK Ege University.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
Structure of a C program
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Basic Elements of C++ Chapter 2.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
Chapter 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
King Saud University College of applied studies and community services CSC 1101 Computer Programming I Lecture 2.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
1 C++ Syntax and Semantics, and the Program Development Process.
Week 1 Algorithmization and Programming Languages.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
1 12/4/1435 h Lecture 2 Programs and Programming Languages.
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.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
A.Abhari CPS1251 Topic 2: C Overview C Language Elements Variable Declaration and Data Types Statement Execution C Program Layout Formatting Output Interactive.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
C Language Elements Preprocessor Directives # (sign for preprocessor directive commands) #include Standard header file (.h) Library.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Numbers in ‘C’ Two general categories: Integers Floats
CSCE 206 Structured Programming in C
Chapter Topics The Basics of a C++ Program Data Types
Introduction to the C Language
Basic Elements of C++.
Revision Lecture
ICS103 Programming in C Lecture 3: Introduction to C (2)
Lecture2.
Basic Elements of C++ Chapter 2.
Introduction to the C Language
Introduction to the C Language
Chapter 2 - Introduction to C Programming
2.1 Parts of a C++ Program.
פרטים נוספים בסילבוס של הקורס
Chapter 2 - Introduction to C Programming
CS111 Computer Programming
Chapter 2 - Introduction to C Programming
Chapter 2: Introduction to C++.
WEEK-2.
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Getting Started With Coding
Presentation transcript:

CC112 Structured Programming Lecture 2 1 Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer Engineering Department

L ECTURE 2 Data Types Assignments Statements 2

L ECTURE O UTLINE i. C Program Structure ii. C Language Elements Preprocessor directives Main Function Header Comments Statements Variable declaration iii. Data Types and Variable Declarations iv. Assignments in C 3

i.C P ROGRAM S TRUCTURE 4 Preprocessor directives Main function prototype { Declarations Statements }

i.C P ROGRAM S TRUCTURE 5 Preprocessor Directives Main function prototype Curly brackets Comments Statements Declarations

II. C L ANGUAGE E LEMENTS 6 Preprocessor Directives Are commands that give instructions to the C preprocessor Begins with a (#) as its nonblank character. C preprocessor is a system program that modifies a C program prior to its compilation. Example1 #include The C language cannot do I/O by itself, so we need help from the library “stdio.h” to use the screen/Keyboard ! We can use other libraries, too, as needed. Another popular “library” is math.h, for advanced math functions.

II. C L ANGUAGE E LEMENTS 7 Preprocessor Directives Example 2 # define PI Define is a preprocessor directives. Valid constant declarations A named constant is a location in memory that we can refer to by a name, and in which a data value that cannot be changed is stored. This directives instructs the processor to replace each occurrence of PI by 3.142

II. C L ANGUAGE E LEMENTS 8 Main Function Prototype The main function of a simple C program is: int main(void) { } This is where the program execution begins. The curly braces mark the beginning and end of the function.

II. C L ANGUAGE E LEMENTS 9 Comments You insert comments to programs in order to improve program readability. Comments also help other people read and understand your program. Comments do not cause the computer to perform any action when the program is run. Begin with /* and ends with */ Or begins only with //

II. C L ANGUAGE E LEMENTS 10 Statements These statements appear in the program body just after the declarations. There purpose is to perform operations such as reading input from the user, displaying output, perform arithmetic operations, etc… Every statement must end with a semicolon (also known as the statement terminator).

II. C L ANGUAGE E LEMENTS 11 Declarations Variable - A name associated with a memory cell whose value can change. - Variables are used to store a program’s input data and its computational results.

II. C L ANGUAGE E LEMENTS 12 Declarations Variable Declaration Statements that communicate to the compiler the names of variables in the program and the type of information stored in each variable. int area;

II. C L ANGUAGE E LEMENTS 13 Declarations Variable Declaration Rules A variable name in C is any valid identifier. An identifier is a series of characters consisting of letters, digits and underscores ( _ ) that does not begin with a digit. C is case sensitive—uppercase and lowercase letters are different in C, so a1 and A1 are different identifiers. C reserved words and standard identifiers cannot be used.

Reserved Word A word that has special meaning in C such as: int void double return Standard Identifiers A word having special meaning but one that a programmer may redefine (but redefinition is not recommended) printf scanf 14 II. C L ANGUAGE E LEMENTS Declarations

Invalid identifiers 1Letter begins with a number double reserved word int reserved word TWO*FOUR character * not allowed joe’s character ‘ not allowed age# character # not allowed Age-of-cat character – is not underscore character (_) Valid Identifiers Age_of_person taxRateY2k PrintHeading 15 II. C L ANGUAGE E LEMENTS Declarations

III.D ATA T YPES AND V ARIABLE D ECLARATIONS Integral Types Whole numbers declared as int, short, or long Int sample values 4578, -4578, 0 Floating Types Real numbers, declared as float, or double Float sample values Character Types Single characters, declared as char Char sample values B d 4 ? * 16

III.D ATA T YPES AND V ARIABLE D ECLARATIONS 17 TYPEDESCRIBTIONEXAMPLEDECLARATION Integral Whole numbers 4578, -4578, 0int, or short FloatingReal numbers 95.27,-95.0 float, or double Character Single characters B d 4 ? * char

III.D ATA T YPES AND V ARIABLE D ECLARATIONS 18 VARIABLE DECLARATIONS EXAMPLE

IV.A SSIGNMENTS IN C 19 The assignment is to store in a variable the results of a computation. The symbol = assignment operator in C. Example: code = ‘B’; i = 14; a=b*c+d;

20