CS 113: Introduction to

Similar documents
Announcements. Java Review. More Announcements. Today. Assembly Language. Machine Language

Welcome to... CS113: Introduction to C

CS 2110 AEW. Machine Language. Outline. Assembly Language. High-Level Language 1/26/2012

CS 2110 AEW SIGN UP FOR 1 CREDIT S/U COURSE!!!

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

Introduction to Computer Systems

EL2310 Scientific Programming

Introduction to Basis and Practice in Programming

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

Spring 2018 NENG 202 Introduction to Computer Programming

CS 241 Data Organization. August 21, 2018

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

10/19/11. Announcements. Java Review. More Announcements. Today A Smorgasbord. Assembly Language. Machine Language. Assignment 1 has been posted

EL2310 Scientific Programming

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

CISC 124: Introduction To Computing Science II

Syllabus of ENPM 691: Secure Programming in C

CS 241 Data Organization using C

Introduction to Computer Systems

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

Course Information and Introduction

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

CS 240 Fall 2015 Section 004. Alvin Chao, Professor

C Programming for Engineers Introduction

Is it ever useful to be confident that a problem is hard?

Java Review. Lecture 2 CS 2110 Fall 2011

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

CS240: Programming in C

LECTURE/ STUDY NOTES ON C

Introduction to Programming

Lecture 1: Preliminaries

CIS* Programming

CS 6371: Advanced Programming Languages

CS120 Computer Science I. Instructor: Jia Song

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims

Introduction to Computer Systems

PROGRAMMAZIONE I A.A. 2017/2018

Introduction to Programming System Design CSCI 455x (4 Units)

CS Prof J.P.Morrison

printf( Please enter another number: ); scanf( %d, &num2);

1/14/2014. Introduction to CSE 1325 Object Oriented Programming (Using Java) Introduction (Cont.) Introduction

CS 140 Programming with Objects

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011

EECE.2160: ECE Application Programming Spring 2019

#include <stdio.h> int main() { printf ("hello class\n"); return 0; }

Fundamentals of Programming (C)

COMP1917: Computing 1 1. Introduction

CS 374 Fall 2014 Homework 2 Due Tuesday, September 16, 2014 at noon

Language Translation, History. CS152. Chris Pollett. Sep. 3, 2008.

CS 3813/718 Fall Python Programming. Professor Liang Huang.

6.S096 Lecture 1 Introduction to C

EECE.2160: ECE Application Programming Spring 2017

Your Instructor. CSE Content. Notes. Notes. Notes. Summer May 4, 2010

Outline. Programming Languages 1/16/18 PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY. Current

Introduction to C. CS 2060 Week 1. Prof. Jonathan Ventura. Outline Introduction Introduction to C Homework 1 C Coding Style Wrap-up

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

CS 0449 Intro to Systems Software Fall Term: 2181

CSE 333 Lecture 1 - Systems programming

Spring 2018 El Camino College E. Ambrosio. Course Syllabus

CS 50 Introduction to Computer Science I

CS 415 Midterm Exam Spring 2002

Welcome to CSE 4300! Spring 2018

Outline. When we last saw our heros. Language Issues. Announcements: Selecting a Language FORTRAN C MATLAB Java

by Pearson Education, Inc. All Rights Reserved.

CS11 Intro C++ Spring 2018 Lecture 1

CS61C : Machine Structures

Preview from Notesale.co.uk Page 6 of 52

Compilers for Modern Architectures Course Syllabus, Spring 2015

ENCE 3241 Data Lab. 60 points Due February 19, 2010, by 11:59 PM

Introduction. A. Bellaachia Page: 1

Topic I. Introduction and motivation References: Chapter 1 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

CS 153 Design of Operating Systems

CS 326: Operating Systems. Lecture 1

Chris Riesbeck, Fall Introduction to Computer Systems

Operating System Labs. Yuanbin Wu

COMP1917: Computing 1 1. Introduction

CS 2505 Fall 2013 Data Lab: Manipulating Bits Assigned: November 20 Due: Friday December 13, 11:59PM Ends: Friday December 13, 11:59PM

AE Computer Programming for Aerospace Engineers

ECEn 424 Data Lab: Manipulating Bits

Introduction to Computer Systems

HW1 due Monday by 9:30am Assignment online, submission details to come

Appendix to Topic IV

ECE 3574: Applied Software Design

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

Lecture 1. Course Overview Types & Expressions

CS 3304 Comparative Languages. Lecture 1: Introduction

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

15-411/ Compiler Design

CS 4120 and 5120 are really the same course. CS 4121 (5121) is required! Outline CS 4120 / 4121 CS 5120/ = 5 & 0 = 1. Course Information

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

CS 356, Fall 2018 Data Lab (Part 1): Manipulating Bits Due: Wednesday, Sep. 5, 11:59PM

Processor. Lecture #2 Number Rep & Intro to C classic components of all computers Control Datapath Memory Input Output

CSE 114, Computer Science 1 Course Information. Spring 2017 Stony Brook University Instructor: Dr. Paul Fodor

Principles of Programming Languages. Lecture Outline

CS 211 Programming I for Engineers

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

Project Data: Manipulating Bits

HUDSON VALLEY COMMUNITY COLLEGE TROY, NEW YORK COURSE OUTLINE

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

Introduction to Computer Systems

Transcription:

CS 113: Introduction to Course information MWF 12:20-1:10pm 1/21-2/15, 306 Hollister Hall Add/drop deadline: 1/28 C Instructor: David Crandall See website for office hours and contact information Prerequisites CS 100 or similar experience with programming Interest in C Patience Lecture 1 C can be frustrating, especially at first CS 113 Spring 2008 But it gets easier with time and practice! 2 Grading CS 113 is 1 credit, S/U grade option only To earn an S, you need to earn the equivalent of a C- A final course score of 70% guarantees an S Grades will be based on: Three programming assignments (75% of grade) One quiz (25% of grade), announced ahead of time Assignments Three programming assignments Graded based on completeness, correctness, style of code Submit assignments via the Course Management System (CMS) Late submissions generally not accepted You may use any C compiler that you wish, e.g. Dev-C++ in CIT labs: 318 Phillips and B7 Upson Eclipse gcc under Windows (Cygwin), Linux, Mac OS Microsoft Visual Studio See website for more information 3 4 Course resources Course website http://www.cs.cornell.edu/courses/cs113 Course newsgroup: cornell.class.cs113 Great place to post questions, discuss assignments, etc. Textbooks Oualline, Practical C Programming. available electronically (for free!) via Cornell Libraries website Reading assignments listed on course website K&R : Kernighan and Ritchie, The C Programming Language. not required, but highly recommended Academic integrity Read and understand AI code on course website We will look for and prosecute AI violations Be especially diligent about assignments You may discuss homework problems with other students at a high level. That is, you may discuss general approaches to a problem, high-level algorithm design, and the general structure of code. However, you may not share written code with any other students except your own partner, nor may you possess code written by another student who is not your partner, either in whole or in part, regardless of format. -- CS 113 website It s pointless to cheat in an S/U course! 5 6

Course objectives Cover major features of C, to the extent that students can subsequently learn about any features not discussed by reading a standard reference. Topics: History, motivation behind C Basic C syntax Variables, data types, operators Functions Pointers Memory management C programming style Debugging The preprocessor Arrays and strings Complex types File I/O Threads Machine Language Used with the earliest electronic computers (1940s) Machines use vacuum tubes instead of transistors Programs are entered by setting switches or reading punch cards All instructions are numbers 0110 0001 0000 0110 Add Reg1 6 An idea for improvement Use words instead of numbers Result: Assembly Language 7 8 Assembly Language High-Level Language Idea: Use a program (an assembler) to convert assembly language into machine code Early assemblers were some of the most complicated code of the time (1950s) ADD R1 6 MOV R1 COST SET R1 0 JMP TOP Typically, an assembler uses 2 passes Idea for improvement Let s make it easier for humans Result: high-level languages 9 Idea: Use a program (a compiler or an interpreter) to convert high-level code into machine code Pro Easier for humans to write, read, and maintain code Con The resulting program will never be as efficient as good assembly-code Waste of memory Waste of time The whole concept was initially controversial FORTRAN (mathematical FORmula TRANslating system) was designed with efficiency very much in mind 10 FORTRAN ALGOL Initial version developed in 1957 by IBM C SUM OF SQUARES ISUM = 0 DO 100 I=1,10 ISUM = ISUM + I*I 100 CONTINUE FORTRAN introduced many high-level language constructs still in use today Variables & assignment Loops Conditionals Subroutines 11 ALGOL = ALGOrithmic Language Developed by an international committee First version in 1958 (not widely used) Second version in 1960 (widely used) ALGOL 60 included recursion Pro: easier to design clear, succinct algorithms Con: too hard to implement; too inefficient Sample code comment Sum of squares begin integer i, sum; for i:=1 until 10 do sum := sum + i*i; end 12

COBOL COBOL = COmmon Business Oriented Language Developed by the US government (about 1960) Design was greatly influenced by Grace Hopper Goal: Programs should look like English Sample code MULTIPLY B BY B GIVING B-SQUARED. MULTIPLY 4 BY A GIVING FOUR-A. MULTIPLY FOUR-A BY C GIVING FOUR-A-C. SUBTRACT FOUR-A-C FROM B-SQUARED GIVING RESULT-1. COMPUTE RESULT-2 = RESULT-1 **.5. COBOL included the idea of records (a single data structure with multiple fields, each field holding a value) Immensely popular language 13 C Developed in 1972 by Dennis Ritchie at Bell Labs Idea was a higher-level language with nearly the power of assembly language Simple, terse syntax for use on machines with little memory Originally used to write UNIX Very widely used Descendents: C++, C#, Objective C, etc. 14 Fortran (1954) C family tree Algol (1958) CPL (1963) Advantages of C Very good for writing fast code Usually much faster than Java, Matlab, etc. Simple syntax BCPL (1967) COBOL (1959) Simula (1964) B (1969) C (1971) Smalltalk (1971) C++ (1983) Objective C (1983) Java (1991) Scheme (1975) Portable and ubiquitous C compilers available on almost any platform Very powerful. Programmer has complete control. C allows operations that other languages don t (e.g. direct access to raw memory addresses) Writing in C or C++ is like running a chain saw with all the safety guards removed. -- Bob Gray C# (2001) 15 16 Disadvantages of C Difficult to learn Memory management is particularly frustrating Difficult to write bug-free, maintainable C code Memory errors are difficult to detect and locate Poor C code is responsible for most of the security holes that worms and viruses exploit C does not enforce good software engineering principles. Hard to use for large programming projects. C/C++ is an atrocity, the bletcherous scab of the computing world, responsible for more buffer overflows, more security breaches, more blue screens of death, more mysterious failures than any other computer language in the history of the planet Earth. -- Eric Lee Green 17 Why learn C? C is the language for systems programming Also very popular for writing applications Although higher-level languages (Java, C#, etc.) are also popular, and often more appropriate Learning C gives you more insight into how programs actually work Pointers and memory addresses Dynamic memory allocation Function calls Other languages (e.g. Java) hide these details 18

stdio.h is the header file for the standard I/O library It contains declarations for many useful functions #include instructs the compiler to read this file #include is similar to import in Java C standard library includes many other header files 19 20 Any C program declares exactly one main function main returns an integer and doesn t take arguments We ll talk about the return value and arguments to main later printf prints to the console Stands for print formatted Declared in stdio.h The \n in the string constant is a newline character 21 22 As in Java, return causes the function to end By convention, C programs return 0 if successful, non-zero if an error occurred 23 24

Declare integer variables named x and y y is declared but not initialized. Q: What is its initial value? A: Undefined! May be different every time the program is run! Why? Initializing takes time. C s philosophy is to be fast as possible (while trading off safety, simplicity). 25 A tangent: C standards C has evolved over time There are three common versions: Original C (1978) K&R C ANSI Standard C (1989) Ansi C Revised ANSI Standard (1999) C99 Example: K&R and ANSI C required variable declarations to appear before any other statements in a function Legal in K&R, Ansi C, C99: int main() int main() Most modern compilers support C99 extensions Legal in C99 only: 26 Comments begin with /* and end with */ Caution: you can t nest comments /* /* /* this works ok */ /* /* /* but this causes an error */ */ */ printf can format and print out values of variables %d is a special placeholder printf substitutes the values of the variables specified as arguments into the placeholders printf has many other options and features 27 28 Getting to know you On the index card, write: Your name and Cornell NetId What you like to be called (nickname?) Your year, college, major Why are you taking 113? CS courses you have taken (+ where and when) Programming languages you have used Any concerns you have about the course 29