CS133 C Programming. Instructor: Jialiang Lu Office: Information Center 703

Similar documents
Programming. Data Structure

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

C Introduction. Comparison w/ Java, Memory Model, and Pointers

Course Information and Introduction

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Presented By : Gaurav Juneja

Software Project. Lecturers: Ran Caneti, Gideon Dror Teaching assistants: Nathan Manor, Ben Riva

Preview from Notesale.co.uk Page 6 of 52

EL2310 Scientific Programming

27-Sep CSCI 2132 Software Development Lecture 10: Formatted Input and Output. Faculty of Computer Science, Dalhousie University. Lecture 10 p.

CSCI 2132 Software Development. Lecture 8: Introduction to C

CS 110 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger.

EL2310 Scientific Programming

CMPE-013/L. Introduction to C Programming

Programming in C. What is C?... What is C?

Programming in C UVic SEng 265

Work relative to other classes

Programming in C. What is C?... What is C?

Computers Programming Course 5. Iulian Năstac

by Pearson Education, Inc. All Rights Reserved.

PROGRAMMAZIONE I A.A. 2017/2018

Programming in C and C++

CSE 303 Lecture 8. Intro to C programming

C Language, Token, Keywords, Constant, variable

Language Design COMS W4115. Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science

Data Structures and Algorithms. Chapter 1

CMSC 246 Systems Programming

CS240: Programming in C

Programming in C and C++

(heavily based on last year s notes (Andrew Moore) with thanks to Alastair R. Beresford. 1. Types Variables Expressions & Statements 2/23

Structure of this course. C and C++ Past Exam Questions. Text books

PRINCIPLES OF OPERATING SYSTEMS

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

The C language. Introductory course #1

Motivation was to facilitate development of systems software, especially OS development.

Introduction to C Language

EC 413 Computer Organization

Motivation was to facilitate development of systems software, especially OS development.

Computer Programming

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Introduction to Basis and Practice in Programming

Language Design COMS W4115. Prof. Stephen A. Edwards Fall 2006 Columbia University Department of Computer Science

Chapter 6 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

Introduction to C Programming

AN OVERVIEW OF C. CSE 130: Introduction to Programming in C Stony Brook University

EL2310 Scientific Programming

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

Introduction to C An overview of the programming language C, syntax, data types and input/output

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

Week 1 / Lecture 2 8 March 2017 NWEN 241 C Fundamentals. Alvin Valera. School of Engineering and Computer Science Victoria University of Wellington

Chapter 11 Introduction to Programming in C

Spring 2018 NENG 202 Introduction to Computer Programming

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

CS 61C: Great Ideas in Computer Architecture Introduction to C

Introduction to Computer Systems

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

BLM2031 Structured Programming. Zeyneb KURT

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

CS 61C: Great Ideas in Computer Architecture Lecture 2: Introduction to C, Part I

CS240: Programming in C. Lecture 2: Overview

Introduction to C programming. By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE

introduction week 1 Ritsumeikan University College of Information Science and Engineering Ian Piumarta 1 / 20 imperative programming about the course

CS 110 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger.

Lecture 3. More About C

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

COMP s1 Lecture 1

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Chapter 11 Introduction to Programming in C

Data Structure. Lecture#2: Data Structures and Algorithms. U Kang Seoul National University. U Kang (2016) 1

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

C++ Programming for Non-C Programmers. Supplement

Chapter 11 Introduction to Programming in C

COMP1917: Computing 1 1. Introduction

Introduction to Computing Lecture 01: Introduction to C

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1

XSEDE Scholars Program Introduction to C Programming. John Lockman III June 7 th, 2012

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language


CSCI 171 Chapter Outlines

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Introduction to Computer Systems

CSCI 2132: Software Development. Norbert Zeh. Faculty of Computer Science Dalhousie University. Introduction to C. Winter 2019

Introduction to C++ with content from

C Overview Fall 2014 Jinkyu Jeong

ET156 Introduction to C Programming

BİL200 TUTORIAL-EXERCISES Objective:

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Introduction to the C Programming Language

Language Reference Manual simplicity

Programming in C week 1 meeting Tiina Niklander

CSC231 C Tutorial Fall 2018 Introduction to C

The C Language Reference Manual

ENCE Computer Organization and Architecture. Chapter 1. Software Perspective

Transcription:

CS133 C Programming Instructor: Jialiang Lu Email: jialiang.lu@sjtu.edu.cn Office: Information Center 703 1

Course Information: Course Page: http://wirelesslab.sjtu.edu.cn/~jlu/teaching/cp2014/ Assignments (HW) Important News Assistant: Fan Yang: xcyangfan@sjtu.edu.c n QQ:445058757 QQ group administrator: 2

Reference books: Programming in C The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie Programming in C (3rd Edition) by Stephen G. Kochan. www.learn-c.org online training Code::Blocks: IDE for C, C++ and Fortain 3

Schedule: 9/17: Introduction to C, Fundamentals 9/24: Type, Operators, Expression 10/1: National Day 10/8: Control Flow & Formatted Input/Output 10/15: TP 10/22: TP 10/29: Functions and Program Structure 11/05: Pointers and Arrays Final exam will take place on Week 10 or 11. 4

WHAT YOU KNOW ABOUT PROGRAMMING? 5

Programming Paradigms 6

Imperative paradigm Programming Paradigms A sequence of commands that, when followed, manipulate data to produce the desired result Declarative paradigm Describe the problem rather than an algorithm Functional paradigm A program is viewed as en entity that accepts inputs and produces outputs Object-Oriented paradigm/programming (OOP) 7

Statements A program consists of a collection of statements Declarative statements int Height, Width; Imperative statements Z = X + Y; if.. else.. Comments //This is an addition /* Declaration of variable*/ 8

Variable and Data Types Variable is used by high-level programming language to be referenced in main memory. Identified by declarative statements int Height, Width; Data type the manner in which the data item is encoded The operations that can be performed on the data. 9

Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely in terms of a set of values and a set of operations on that data type. Each ADT operation is defined by its inputs and outputs. Encapsulation: Hide implementation details. 10

Data Structure A data structure is the physical implementation of an ADT. Each operation associated with the ADT is implemented by one or more subroutines in the implementation. Data structure usually refers to an organization for data in main memory. File structure is an organization for data on peripheral storage, such as a disk drive. 11

Metaphors An ADT manages complexity through abstraction: metaphor. Hierarchies of labels Ex: transistors gates CPU. In a program, implement an ADT, then think only about the ADT, not its implementation. 12

Logical vs. Physical Form Data items have both a logical and a physical form. Logical form: definition of the data item within an ADT. Ex: Integers in mathematical sense: +, - Physical form: implementation of the data item within a data structure. Ex: 16/32 bit integers, overflow. 13

Data Type ADT: Type Operations Data Items: Logical Form Data Structure: Storage Space Subroutines Data Items: Physical Form 14

Common data structure Array A block of elements of the same type One-dimension/two-dimension/etc. Int Scores[?][?][?] for premierleague Aggregate type Different elements can have different types Struct {char Name[25]; int Age; float SkillRating;} Employee; 15

Procedure Units A procedure is a set of instructions for performing a task that can be used as an abstract tool by other program units. 16

An example of Procedure 17

The translation process From source program to object program.c.o.java.class Lexical analyzer find token Parser Group units into statements Generating a parse tree Code generator Code optimization Source Program Lexical analyzer Parser Code generator Object Program tokens parse trees 18

SO YOU THINK YOU KNOW C? 19

A little history: 1970 s Unix C, from BCPL (Thompson and Ritchie) C programming Language Widely used like the others: Fortran, Pascal Main form of language for system programming Available on any machine with C compiler and library 20

Some Characteristics: Scope: Intended: HPC, OS, general programming Typically, long developing cycle very platform dependent Not intended: web, scripting, data processing Features: Close interaction with system Standard library (user-level only), no other fancy stuff: networking, memory, graphics Extensive use of pointers Procedure programming, strictly pass by value 21

Sample 1: /* Hello World! */ #include <stdio.h> int main() { printf( Hello World!\n ); return 0; } 22

Walk through: C program: hello.c emacs, vi, vim, pico, joe But text editors only. No word processor Preprocessing: hello.s, assembly code cc -S hello.c Compilation: hello.o, a binary file cc -c hello.s Linking: a.out or hello, an executable file cc hello.o cc -o hello hello.o Loading (dynamical linking) and execution:./hello./a.out./hello 23

A typical execution of a piece of C program 24

Sample 1 Dissection: What it has? A function definition: main A line of comment A line of preprocessor directive An output statement A return clause What it does? Ask the computer to say hello to the world. What it does not do? It seems not computing!! No real work not taking input does not change any value 25

Sample 2: #include <stdio.h> #define MAGIC 10 int main(void) { int i, fact, quotient; while (i++ < 3) { } printf( Guess a factor of MAGIC larger than 1: "); scanf("%d, &fact); quotient = MAGIC % fact; if (0 == quotient) else printf( You got it!\n ); printf( Sorry, You missed it!\n ); return 0; } 26

Sample 2 Dissection: What more it has? Macro definition Variable declaration Operations represented by operators Conditional computation Input Processing Loops: three chances 27

Syntax Dissection: What is syntax? m-w.com: the way in which linguistic elements (as words) are put together to form constituents (as phrases or clauses) How to put your C elements together into a program? Variable declaration, Identifier: case, keywords, style datatype specification Operators: char, short, int, long, float, double +, -, *, /, %, ++, --; >, <, ==, ; &,, Priority and Precedence Associativity 28

More Syntax Dissection: Preprocessor directive macro header file inclusion Loop constructs for, while, do-while, break, continue, label--go; Conditional statements If, else, else if, switch, break Function definition return type, parameter definition, parameter passing Standard library and function calls 29

A BREAK: CODE::BLOCKS 30