Introduction to Systems Programming - Recitation Omer Kotlicki Two instances: 1.Tuesdays 15:00-16:00; Kitot 206 2.Wednesdays.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Lecture 09 Strings, IDEs. METU Dept. of Computer Eng. Summer 2002 Ceng230 - Section 01 Introduction To C Programming by Ahmet Sacan Mon July 29, 2002.
Lecture 9. Lecture 9: Outline Strings [Kochan, chap. 10] –Character Arrays/ Character Strings –Initializing Character Strings. The null string. –Escape.
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
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Dale/Weems/Headington
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
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.
To remind us We finished the last day by introducing If statements Their structure was:::::::::
CSSE221: Software Dev. Honors Day 28 Announcements Announcements Simulation grades coming back Simulation grades coming back All C Projects due Friday.
C. About the Crash Course Cover sufficient C for simple programs: variables and statements control functions arrays and strings pointers Slides and captured.
Introduction to Computers and Programming - Class 2 1 Introduction to Computers and Programming Class 2 Introduction to C Professor Avi Rosenfeld.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
C Slides and captured lecture (video and sound) are available at:
Chapter 8 Arrays and Strings
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
Basic Input/Output and Variables Ethan Cerami New York
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
Computer Science 210 Computer Organization Introduction to C.
CS 11 C track: lecture 1 Preliminaries Need a CS cluster account cgi-bin/sysadmin/account_request.cgi Need to know UNIX ITS.
Strings in C. Strings are Character Arrays Strings in C are simply arrays of characters. – Example:char s [10]; This is a ten (10) element array that.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Chapter 9 Character Strings 9.1 Character String Constants A character string constant is a sequence of characters enclosed in double quotation mark. Examples.
C Programming Tutorial – Part I CS Introduction to Operating Systems.
Programming I Introduction Introduction The only way to learn a new programming language is by writing programs in it. The first program to.
C Programming n General Information on C n Data Types n Arithmetic Operators n Relational Operators n if, if-else, for, while by Kulapan Waranyuwat.
JAVA 0. HAFTA Algorithms FOURTH EDITION Robert Sedgewick and Kevin Wayne Princeton University.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
 2000 Prentice Hall, Inc. All rights reserved Arrays Array –Group of consecutive memory locations –Same name and type To refer to an element, specify.
Spring 2005, Gülcihan Özdemir Dağ Lecture 7, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 7 Outline 7. 1.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 5.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Lecture 22: Reviews for Exam 2. Functions Arrays Pointers Strings C Files.
Representing Strings and String I/O. Introduction A string is a sequence of characters and is treated as a single data item. A string constant, also termed.
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
Strings Programming Applications. Strings in C C stores a string in a block of memory. The string is terminated by the \0 character:
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
© 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,
Lecturer: Nguyen Thi Hien Software Engineering Department Home page: hienngong.wordpress.com Chapter 2: Language C++
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 5 : September 4.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
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.
Computer Science 210 Computer Organization
- Standard C Statements
Chapter 2 - Introduction to C Programming
Revision Lecture
Chapter 2 - Introduction to C Programming
Computer Science 210 Computer Organization
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to CS Your First C Programs
Chapter 2 - Introduction to C Programming
CS111 Computer Programming
Introduction to C Programming
Chapter 2 - Introduction to C Programming
Differences between Java and C
Introduction to C Programming
Chapter 2 - Introduction to C Programming
Dale Roberts, Lecturer IUPUI
Introduction to C Programming
Presentation transcript:

Introduction to Systems Programming - Recitation Omer Kotlicki Two instances: 1.Tuesdays 15:00-16:00; Kitot Wednesdays 11:00-12:00; Kitot 206 Reception: Wednesdays 12:00-13:00 - room #32 at the nano center (under the library)

Avishai Wool Lecture Administrivia Course home page: Course Mailing list: Books Modern Operating Systems, 3 rd edition, by Tanenbaum. Prentice- Hall, nd edition (2001) is fine too. Grades Final exam 65% Exercises 35%

Avishai Wool Lecture Administrivia – cont. Significant programming in C 3-4 exercises + final project Windows programming environment (Microsoft VC++ / Visual Studio) Assignments in pairs Sharing / copying exercises will NOT be tolerated

About the Crash Course Created by Prof. Cooperstock from McGill University, Montreal Cover sufficient C for simple programs: variables and statements control functions arrays and strings pointers Slides and captured lecture (video and sound) are available at:

Why C? C is not always a good choice... Safety-critical systems Component-based programming / RAD but in many applications you do want C Legacy systems Speed, memory requirements Low-level programming (close to the machine)...

Your First C Program "The only way to learn a new programming language is by writing programs in it" [K&R] /* A simple program that prints something */ #include main () { printf ("Hello, world!\n"); }

Declarations Example: float x; double d = 5; int *p, i, a[100]; char s[21]; Syntax: type variable_name,... [= value]; Rules: declarations must precede executable statements int type may be modified by: long, short, unsigned

Changing Variable Values Example: int x, y, z; x = 2; x = x + 1; Getting Fancy y = z = 4 + 5; x += 1; ++x; x++; y = x--; Note: assignment statements return value, which may or may not be ignored; same goes for increment statements

Formatted Output Example: int i = 10; float f = 2.5; char s [] = "hi"; printf ("Jack\'s integer is %d\n", i); printf ("Jill\0x27s float is %f\n", f); printf ("My string s = %s\n", s); Syntax: printf (string_with_formatting, var1, var2,...); Formats: %d integer, %f float, %c character, %s string, … Note "escape sequences": \n newline, \' quote, \0x27, etc. #include is compulsory; more about it later

Formatted Input Example: #include int i; float f; scanf ("%d %f\n", &i, &f); /* inputs an integer and a float */ Syntax: scanf (string_with_formatting, &var1, &var2,...); Note: The ampersand ( & ) is necessary because scanf modifies the values stored in the respective variables; by comparison, printf only uses the values, without modifying them. More about this later

I/O Example What does this print? #include main () { int n; float x; char mark; scanf ("%d %f %c", &n, &x, &mark); printf ("Of %d %s,\n%f got %c\’s\n", n, "students", x, mark); } Type in the following input: A

I/O Example #include main () { int n; float x; char mark; scanf ("%d %f %c", &n, &x, &mark); printf ("Of %d %s,\n%f got %c\’s\n", n, "students", x, mark); } Input : A Output : Of 86 students, got A's

Conditional Statements Example: if (age < 0) { printf ("warning: negative age\n"); age = -age; } Syntax: if (condition) statement if (condition) statement else statement Rules: the condition is an int ! (no booleans) parentheses required around conditional expression use curly braces to make a compound statement

More Conditionals Example: if (x < 0) printf ("x is less than 0\n"); else if (x == 0) printf ("x is equal to 0\n"); else printf ("x is greater than 0\n"); What’s wrong with this? if (x < 0) if (y < z) printf ("y is less than z\n"); else printf ("x not less than 0\n");

While Loops Example: /* print "hi" forever */ while (1) printf ("hi"); Syntax: while (condition) statement Rules (again): the condition is an int ! (no booleans) parentheses required around conditional expression use curly braces to make a compound statement

For Loops Example: /* print "hi" three times */ int i; /* i continues to exist when loop ends */ for (i = 0; i < 3 ; i++) printf ("hi"); Syntax: for (statement1; condition; statement2) statement3; Equivalent to: statement1; while (condition) { statement3; statement2; }

Loop Example /* print squares up to 100 */ main ( ) { int j, up = 100; for (j = 0; j * j <= up; j++) printf ("%d \n", j * j); } Note: can’t do: for (int j = 0;... waste of one multiplication per iteration can you make it more efficient?

Example (cont’d) /* print squares up to 100 */ void main ( ) { int j, up = 100, sq; for (j = 0; (sq = j * j) <= up; j++) printf ("%d \n", sq); } Note: recall equivalence to a while loop: condition is evaluated before the loop body

Arrays int years[45]; float temperatures [11]; void main () { years[0] = 2000; temperatures[11] = ; } Rules: indices start at zero maximum valid index is the size of the array minus 1 but C lets you go beyond the declared boundaries temperatures[11] is illegal

Characters char a, b, c1, c2; a = '0'; b = '\037'; c1 = 'K'; c2 = c1 + 1; Assigns values: 48, 31, 75, 76 The sequences '0',...,'9', 'a',...,'z', 'A',...,'Z' contain characters numbered consecutively Casting printf ("%c %d\n", c1, (int) c1); Outputs: K 75

Strings Strings are '\0' -terminated arrays of char : char s[3] = "hi"; /* invisible '\0' */ char t[3] = {'h', 'i', '\0'}; String operations #include strlen ("there"); /* returns 5 */ strcpy (s, t); /* copy t to s */ strcmp (s, t) /* alphabetical comparison */