IS12 - Introduction to Programming. Lecture 7: Introduction to C

Similar documents
EL2310 Scientific Programming

Computers and Computation. The Modern Computer. The Operating System. The Operating System

EL2310 Scientific Programming

Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Instructor. Mehmet Zeki COSKUN Assistant Professor at the Geodesy & Photogrammetry, Civil Eng. (212)

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

Programming I Laboratory - lesson 01

Section 2.2 Your First Program in Java: Printing a Line of Text

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

CS Prof J.P.Morrison

Topic 1: Programming concepts

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

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

COMP1917: Computing 1 1. Introduction

CSE 303 Lecture 8. Intro to C programming

1. Introduction. Course Web Site. COMP1917: Computing 1. Textbook. Occupational Health and Safety (OHS)

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

Full file at

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

EL2310 Scientific Programming

EC 413 Computer Organization

Fundamentals of Programming. Lecture 3: Introduction to C Programming

COP4020 Programming Assignment 1 - Spring 2011

COMP1917: Computing 1 1. Introduction

CS 241 Data Organization. August 21, 2018

Using Eclipse and Karel

C Introduction Lesson Outline

IS12 - Introduction to Programming

Chapter 2, Part I Introduction to C Programming

Chapter 1 Lab Algorithms, Errors, and Testing

A function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3).

CS 253: Intro to Systems Programming 1/21

CMPT 115. C tutorial for students who took 111 in Java. University of Saskatchewan. Mark G. Eramian, Ian McQuillan CMPT 115 1/32

1007 Imperative Programming Part II

CS 102 Lecture 1. Syllabus, history, intro

(0) introduction to the course. how to learn a programming language. (0) course structure

Course Outline. Introduction to java

Section 2.2 Your First Program in Java: Printing a Line of Text

Unit 7: Algorithms and Python CS 101, Fall 2018


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

We first learn one useful option of gcc. Copy the following C source file to your

CSCI 2132 Software Development. Lecture 8: Introduction to C

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

COMP s1 Lecture 1

CS 190C: Introduction to Computational Thinking

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

Computer Hardware. Java Software Solutions Lewis & Loftus. Key Hardware Components 12/17/2013

CS 211 Programming I for Engineers

Chapter 2. Basics of Program Writing

COMP 202 Java in one week

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

Running a C program Compilation Python and C Variables and types Data and addresses Functions Performance. John Edgar 2

Full file at

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

Programming in C UVic SEng 265

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

CSCI 4152/6509 Natural Language Processing Lecture 6: Regular Expressions; Text Processing in Perl

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

Introduction to Computer Programming for Non-Majors CSC 2301, Fall The Department of Computer Science

Typescript on LLVM Language Reference Manual

Programming 1. Lecture 1 COP 3014 Fall August 28, 2017

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

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

Python Programming: An Introduction to Computer Science

Algorithms and Programming I. Lecture#12 Spring 2015

Problem Solving With C++ Ninth Edition

Computer Science II Lecture 1 Introduction and Background

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

Chapter 1 & 2 Introduction to C Language

Chapter 1: A First Program Using C#

Week 3. This is CS50. Harvard University. Fall Cheng Gong

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

CS 177 Recitation. Week 1 Intro to Java

Introduction to Computer Programming for Non-Majors

Computer Science 50 Introduction to Computer Science I. Week 0

MEIN 50010: Python Introduction

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Laboratory 1: Eclipse and Karel the Robot

Introduction. Introduction to OOP with Java. Lecture 01: Introduction to OOP with Java - AKF Sep AbuKhleiF -

CS110: PROGRAMMING LANGUAGE I

ENGR/CS 101 CS Session Lecture 3

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

Using the Dev C++ Compiler to Create a Program

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to:

QUIZ: What value is stored in a after this

Professor Peter Cheung EEE, Imperial College

Using Karel with Eclipse

CSCE 145, Sections 4, 5, 6 Study Guide Second Midterm

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Fundamentals of Programming Session 4

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

C: How to Program. Week /Mar/05

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

Linux Systems Administration Shell Scripting Basics. Mike Jager Network Startup Resource Center

Curriculum Map Grade(s): Subject: AP Computer Science

CSE 303: Concepts and Tools for Software Development

Transcription:

IS12 - Introduction to Programming Lecture 7: Introduction to C Peter Brusilovsky http://www2.sis.pitt.edu/~peterb/0012-072/ Lecture 7: Introduction to C. Overview C vs. other languages Information representation Let s start First C program (Hello, World!) Edit-compile-run loop again Errors and modifications Knowledge Tree as a great help for us 1

Why C? Modular procedural language with arrays, structures, and references C vs. Pascal modern, portable, better textbooks and tools employment prospects (C, C++, Java) C vs. C++ or Java small, clean, simple explains what is behind data structures and other high-level objects provides an easy transfer to C++ and Java Commands and data Components of a program Objects (data) Commands (instructions) This is true on several levels Basic features of a machine language or a programming language: Ways to represent objects - data types Ways to act on information - operations 2

Karel vs. C Data Karel - location, beepers, walls C - numbers and symbols in memory Commands Karel - move, turnleft C - add, print Karel operates in a visible word outside; C programs work invisibly inside Information Representation Computer store information digitally in binary format Ultimately everything is ones and zeroes characters, numbers instructions (programs!!) pictures, video Binary arithmetic E.g., 7 = 00000111 99 = 01100011 3

From Commands to Algorithms machine commands 0100 0001101 10001110 high-level language commands a = 16; printf("hello!\n ); basic control structures while for if-else switch simple patterns average maximum string reading algorithms sorting binary search matching Learning C Be careful, read your programs! The basic philosophy of C: "programmers know what they are doing" - K&R2, p.3 Ask questions in CourseWeb forums Meet your instructor during the office hours Practice, practice, practice! Run all examples, modify it Solve problems, check yourself on quizzes Books: See Course Books page Tools: Editor+Compiler - See Course Tools page 4

Start Dev C++ Start -> All Programs -> Programming Tools - > Bloodshed Dev C++ -> Dev C++ Click New Program (blank page) Let s write, save, compile and run our first C program Continue prectice at home: Install editor-compiler or IDE Compile and run Hello, World! program Experiment: print your name, make errors, etc. Hello World Program Dissection adapted From S. Pilachewski 5

Working with Command Prompt 1. Start->Run->cmd, or Start -> All Programs -> Accessories - >Command Prompt 2. cd \ 3. cd temp 4. mkdir IS12 5. cd IS12 Save and Run In Dev C++: Save Select My Computer-> Hard Disk (C:) Compile In Command Prompt: dir (lets you check that.exe is here) name-of-the-program (runs the program) Alternatively run in Dev C++ system( PAUSE ); 6

C Program Syntax Most C programs have the following (at minimum): main ([program arguments]) <one or more statements> Every program must have a main function. Note that C is case sensitive (Main is not the same as MAIN or main). Hello World - dissected This is a comment. Comments are written not for computers but for humans. The computer will ignore everything between /* and */. Humans need comments to understand the program. (Why?) 7

Hello World - dissected #include is a command which tells the compiler that the standard input / output library will be used. Thus printf will be recognized as a standard output function Hello World - Function Execution of a C program always begins at the function. Every C program must have one (only one) function. 8

Hello World - the Braces The open brace () marks the beginning of the function body, which is one or more program statements which perform some task. The closing brace () marks the end of the function body. Hello World - the printf statement This statement is a function call to the printf function in the C Standard I/O Library. It displays the message which is the argument to the function. The \n denotes the newline. We can use printf because we told the compiler to use Standard I/O Library in #include 9

Hello World - the semicolon The semicolon marks the end of a C program statement. The edit-compile loop again 1. Edit program 2. Compile program 3. If there are errors, fix and go back to 1 you have got syntax error fix and go back to 1 4. Run it 5. If it produce wrong results you have got semantic error find the source of the error (debug) fix and go back to 1 10

The iterative nature of program design The programming in small loop Edit Compile Run Test/Debug Hello World - Syntax Error printf("hello World!\n") The semicolon is missing What happens when we compile this? 11

Hello World - Experiment 2 /* note the absence of \n */ printf("hello World"); system( PAUSE ); What happens when we run this? Hello World - Experiment 3 /* note the extra \n */ printf( Hello\n World\n ); What happens when we run this? 12