C Primer Plus 5/e 1.1 C
|
|
- Erica Fleming
- 6 years ago
- Views:
Transcription
1 C Primer Plus 5/e 1.1 C C C 2
2 2 C int main() // traditional rules int doors; int dogs; doors = 5; dogs = 3; // other statements int main() // C99 rules // some statements int doors; doors = 5; // first use of doors // more statements int dogs; dogs = 3; // first use of dogs // other statements 33
3 2 C n3 = n2 * n2; 47
4 3 C void main(int) / this program is perfect / cows, legs integer; printf( How many cow legs did you count?\n); scanf( %c, legs); cows = legs / 4; printf( That implies there are %f cows.\n, cows) Startled by the sudden sound, Sally shouted, By the Great Pumpkin, what was that! 101
5 C Primer Plus 5/e What is the radius of your pizza? 6.0 Your basic pizza parameters are as follows: circumference = 37.70, area = #define BEEP \a #define TEE T #define ESC \033 #define OOPS Now you have done it! /* the following is wrong */ #define TOES = 20 digits = fingers + TOES; digits = fingers + = 20; const const int MONTHS = 12; // MONTHS a symbolic constant for 114
6 4 scanf() 4.14 input.c // input.c -- when to use & #include <stdio.h> int main(void) int age; // variable float assets; // variable char pet[30]; // string printf( Enter your age, assets, and favorite pet.\n ); scanf( %d %f, &age, &assets); // use the & here scanf( %s, pet); // no & for char array printf( %d $%.2f %s\n, age, assets, pet); return 0; 133
7 5 shoe = 3.0; while (shoe < 18.5) foot = SCALE*size + ADJUST; printf( %10.1f %20.2f inches\n, shoe, foot); ++shoe; shoe = 2.0; while (++shoe < 18.5) foot = SCALE*shoe + ADJUST; printf( %10.1f %20.2f inches\n, shoe, foot); while shoe 3 true
8 bottles.c printf( Take one down and pass it around,\n ); printf( %d bottles of spring water!\n\n, count - 1); return 0; 100 bottles of spring water on the wall, 100 bottles of spring water! Take one down and pass it around, 99 bottles of spring water! 99 bottles of spring water on the wall, 99 bottles of spring water! Take one down and pass it around, 98 bottles of spring water! 1 bottles of spring water on the wall, 1 bottles of spring water! Take one down and pass it around, 0 bottles of spring water! 173
9 running.c // converts time to pure seconds time = S_PER_M * min + sec; // converts kilometers to miles distm = M_PER_K * distk; // miles per sec x sec per hour = mph rate = distm / time * S_PER_H; // time/distance = time per mile mtime = (double) time / distm; mmin = (int) mtime / S_PER_M; // find whole minutes msec = (int) mtime % S_PER_M; // find remaining seconds printf( You ran %1.2f km (%1.2f miles) in %d min, %d sec.\n, distk, distm, min, sec); printf( That pace corresponds to running a mile in %d min,, mmin); printf( %d sec.\nyour average speed was %1.2f mph.\n,msec, rate); return 0; This program converts your time for a metric race to a time for running a mile and to your average speed in miles per hour. Please enter, in kilometers, the distance run Next enter the time in minutes and seconds. Begin by entering the minutes. 36 Now enter the seconds. 191
10 9 ***************************************************************** 1) Fairfield Arms 2) Hotel Olympic 3) Chertworthy Plaza 4) The Stockton 5) quit ***************************************************************** 3 How many nights are needed? 1 The total cost will be $ ***************************************************************** Enter the number of the desired hotel: 1) Fairfield Arms 2) Hotel Olympic 3) Chertworthy Plaza 4) The Stockton 5) quit ***************************************************************** 4 How many nights are needed? 3 The total cost will be $ ***************************************************************** Enter the number of the desired hotel: 1) Fairfield Arms 2) Hotel Olympic 3) Chertworthy Plaza 4) The Stockton 5) quit ***************************************************************** 5 while ((status = scanf( %d, &code))!= 1 (code < 1 code > 5)) 395
11 C Primer Plus 5/e c z 3 int main(void) double q, x, duff(); /* declare in calling function */ int n;... q = duff(x,n);... double duff(u, k) /* declare in function definition */ double u; int k; double tor;... return tor; /* returns a double value */ 408
12 10 dates + 2 == &date[2] /* same address */ *(dates + 2) == dates[2] /* same value */ *(dates + 2) /* value of the 3rd element of dates */ *dates + 2 /* 2 added to the value of the 1st element */ 10.9 day_mon3.c /* day_mon3.c -- uses pointer notation */ #include <stdio.h> #define MONTHS 12 int main(void) int days[months] = 31,28,31,30,31,30,31,31,30,31,30,31; int index; for (index = 0; index < MONTHS; index++) printf( Month %2d has %d days.\n, index +1, *(days + index)); // same as days[index] return 0; 433
13 C Primer Plus 5/e show_array(rates, 5); show_array(locked, 4); // valid // valid mult_array(rates, 5, 1.2); mult_array(locked, 4, 1.2); // valid // not allowed double rates[5] = 88.99, , 59.45, , 340.5; double * const pc = rates; // pc points to beginning of the array pc = &rates[2]; // not allowed *pc = 92.99; // ok -- changes rates[0] double rates[5] = 88.99, , 59.45, , 340.5; const double * const pc = rates; pc = &rates[2]; // not allowed *pc = 92.99; // not allowed 450
14 10 int * p1; const int * p2; const int ** pp2; p1 = p2; // not valid -- assigning const to non-const p2 = p1; // valid -- assigning non-const to const pp2 = &p1; // not valid -- assigning non-const to const p2 = p1; // valid -- assigning non-const to const const int **pp2; int *p1; const int n = 13; pp2 = &p1; // not allowed, but suppose it were *pp2 = &n; // valid, both const, but sets p1 to point at n *p1 = 10; // valid, but changes const n 457
15 12 extern char permis = Y ; /* error */ static int svil = 1; // static variable, internal linkage int main(void) int traveler = 1; // external linkage static int stayhome = 1; // internal linkage int main() extern int traveler; // use global traveler extern int stayhome;..// use global stayhome 555
16 firms2.c /* films2.c -- using a linked list of structures */ #include <stdio.h> #include <stdlib.h> /* has the malloc prototype */ #include <string.h> /* has the strcpy prototype */ #define TSIZE 45 /* size of array to hold title */ struct film char title[tsize]; int rating; struct film * next; /* points to next struct in list */ ; int main(void) struct film * head = NULL; struct film * prev, * current; char input[tsize]; puts( Enter first movie title: ); while (gets(input)!= NULL && input[0]!= \0 ) current = (struct film *) malloc(sizeof(struct film)); if (head == NULL) /* first structure */ head = current; else /* subsequent structures */ prev->next = current; current->next = NULL; strcpy(current->title, input); puts( Enter your rating <0-10>: ); scanf( %d, ¤t->rating); while(getchar()!= \n ) continue; puts( Enter next movie title (empty line to stop): ); prev = current; if (head == NULL) printf( No data entered. ); else printf ( Here is the movie list:\n ); current = head; while (current!= NULL) printf( Movie: %s Rating: %d\n, current->title, current->rating); current = current->next; 665
17 14 union hold vala; vala.letter = R ; union hold valb = vala; // initialize one union to another union hold valc = 88; // initialize digit member of union union hold vald =.bigfl = 118.2; // designated initializer pu = &fit; x = pu->digit; // same as x = fit.digit fit.digit = 23; // 23 is stored in fit; 4 bytes used fit.bigfl = 2.0; // 23 cleared, 2.0 stored; 8 bytes used fit.letter = h ; // 2.0 cleared, h stored; 1 byte used fit.letter = A ; flnum = 3.02*fit.bigfl; // ERROR ERROR ERROR 671
18 C Primer Plus 5/e typedef struct complex float real; float imag; COMPLEX; typedef struct double x; double y; rect; rect r1 = 3.0, 6.0; rect r2; struct double x; double y; r1= 3.0, 6.0; struct double x; double y; r2; r2 = r1; typedef char (* FRPTC ()) [5]; 680
19 C Primer Plus 5/e val &= 0377; val = val & 0377; OR ( ) ( ) // ( ) // val = 0377; val = val 0377; OR ^ 696
20 16 C C #include <stdio.h> #include mystuff.h #include <stdio.h> #include hot.h #include /usr/biff/p.h /usr/biff 729
21 A printf Where are the parentheses? ;. 759
22 A #define P(X) printf( name: #X ; value: %d; address: %p\n, X, &X) #define _SKIP_ /* */ #ifndef _SKIP_ /* */ #endif #ifdef PR_DATE printf( Date = %s\n, DATE ); #endif enum days visit; 797
BSM540 Basics of C Language
BSM540 Basics of C Language Chapter 4: Character strings & formatted I/O Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture To explain the input/output functions printf()
More informationC BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.
C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,
More informationVariables Data types Variable I/O. C introduction. Variables. Variables 1 / 14
C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition
More informationMemory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables)
Memory Allocation Memory What is memory? Storage for variables, data, code etc. How is memory organized? Text (Code) Data (Constants) BSS (Global and static variables) Text Data BSS Heap Stack (Local variables)
More informationProgramming. Structures, enums and unions
Programming Structures, enums and unions Summary } Structures } Declaration } Member access } Function arguments } Memory layout } Array of structures } Typedef } Enums } Unions 2 Idea! } I want to describe
More informationET156 Introduction to C Programming
ET156 Introduction to C Programming Unit 1 INTRODUCTION TO C PROGRAMMING: THE C COMPILER, VARIABLES, MEMORY, INPUT, AND OUTPUT Instructor : Stan Kong Email : skong@itt tech.edutech.edu Figure 1.3 Components
More informationThe C Programming Language Part 4. (with material from Dr. Bin Ren, William & Mary Computer Science, and
The C Programming Language Part 4 (with material from Dr. Bin Ren, William & Mary Computer Science, and www.cpp.com) 1 Overview Basic Concepts of Pointers Pointers and Arrays Pointers and Strings Dynamic
More informationActually, C provides another type of variable which allows us to do just that. These are called dynamic variables.
When a program is run, memory space is immediately reserved for the variables defined in the program. This memory space is kept by the variables until the program terminates. These variables are called
More informationType Definition. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18
Enum and Struct Type Definition C Types Derived Function Array Pointer Structure Union Enumerated 2 tj Type Definition Typedef Define a new Type Inherits members and operations from a standard or previously
More informationC Language Part 3. Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 3 Pointers (revisited) int i = 4, j = 6, *p = &i, *q = &j, *r; if (p == &i)...; if (p == (& i))...;... = **&p;... = *(*(& p));... = 9 * *p / *q + 8;... = (((9*(*p)))/(*q)) + 8; *(r = &i)
More informationKurt Schmidt. October 30, 2018
to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed
More informationCS61, Fall 2012 Section 2 Notes
CS61, Fall 2012 Section 2 Notes (Week of 9/24-9/28) 0. Get source code for section [optional] 1: Variable Duration 2: Memory Errors Common Errors with memory and pointers Valgrind + GDB Common Memory Errors
More informationCSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine
More informationSample Examination. Family Name:... Other Names:... Signature:... Student Number:...
Family Name:... Other Names:... Signature:... Student Number:... THE UNIVERSITY OF NEW SOUTH WALES SCHOOL OF COMPUTER SCIENCE AND ENGINEERING Sample Examination COMP1917 Computing 1 EXAM DURATION: 2 HOURS
More information2/28/2018. Overview. The C Programming Language Part 4. Pointers. Pointers. Pointers. Pointers
Overview The C Programming Language Part 4 (with material from Dr. Bin Ren, William & Mary Computer Science, and www.cpp.com) Basic Concepts of and Arrays and Strings Dynamic Memory Allocation 1 2 pointer
More informationMidterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:
Page 1 of 8 School of Computer Science 60-141-01 Introduction to Algorithms and Programming Winter 2015 Midterm Examination # 2 Wednesday, March 18, 2015 ANSWERS Duration of examination: 75 minutes STUDENT
More informationMidterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.
Midterm Exam Nov 8th, 2012 COMS W3157 Advanced Programming Columbia University Fall 2012 Instructor: Jae Woo Lee About this exam: - There are 4 problems totaling 100 points: problem 1: 30 points problem
More information#ifndef DOUBLE_LIST /* this string SHOULD NOT previously exist */ #define DOUBLE_LIST
/* This is a personal header file. Call it double_list.h * Its name should be reflected into the macro definition (#define). * For instance, here I should say something like: * #define DOUBLE_LIST #ifndef
More informationCS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco
CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level
More informationSubject: Fundamental of Computer Programming 2068
Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find
More informationOutline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C
Lecture 1 C primer What we will cover A crash course in the basics of C You should read the K&R C book for lots more details Various details will be exemplified later in the course Outline Overview comparison
More informationSOFTWARE Ph.D. Qualifying Exam Spring Consider the following C program, which includes three function definitions, including the main function.
(i) (6 pts.) SOFTWARE Ph.D. Qualifying Exam Spring 2017 Consider the following C program, which includes three function definitions, including the main function. #include #include
More informationCOMP1917 Computing 1 Written Exam Sample Questions
COMP1917 Computing 1 Written Exam Sample Questions Note: these sample questions are intended to provide examples of a certain style of question which did not occur in the tutorial or laboratory exercises,
More informationSOFTWARE Ph.D. Qualifying Exam Fall 2017
(i) (4 pts.) SOFTWARE Ph.D. Qualifying Exam Fall 2017 Consider the following C program. #include #define START 2 #define LIMIT 60 #define STEP 7 #define SIZE 3 int main(void) { int i = START,
More informationFloating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions
Announcements Thursday Extras: CS Commons on Thursdays @ 4:00 pm but none next week No office hours next week Monday or Tuesday Reflections: when to use if/switch statements for/while statements Floating-point
More informationChapter 2: Overview of C. Problem Solving & Program Design in C
Chapter 2: Overview of C Problem Solving & Program Design in C Addison Wesley is an imprint of Why Learn C? Compact, fast, and powerful High-level Language Standard for program development (wide acceptance)
More informationTopic 6: A Quick Intro To C
Topic 6: A Quick Intro To C Assumption: All of you know Java. Much of C syntax is the same. Also: Many of you have used C or C++. Goal for this topic: you can write & run a simple C program basic functions
More informationCOP 3223 Introduction to Programming with C - Study Union - Fall 2017
COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................
More informationC programming basics T3-1 -
C programming basics T3-1 - Outline 1. Introduction 2. Basic concepts 3. Functions 4. Data types 5. Control structures 6. Arrays and pointers 7. File management T3-2 - 3.1: Introduction T3-3 - Review of
More informationCC112 Structured Programming
Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer Engineering Department CC112 Structured Programming Lecture 3 1 LECTURE 3 Input / output operations
More informationCOMP 2355 Introduction to Systems Programming
COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Functions Similar to (static) methods in Java without the class: int f(int a, int
More informationIntroduction to Data Structures. Systems Programming
Introduction to Data Structures Systems Programming Intro to Data Structures Self-referential Structures Dynamic Memory Allocation A Simple malloc Example Linear Lists Linked Lists Insertion Example Linked
More informationChapter 6. Data Structure. /* start contains the address of the first node */ start = &elephant1; print_elephants( start ); return EXIT_SUCCESS;
Chapter 6 Data Structure Introductory notes are included in PowerPoint file. The programs illustrated are as follows: //elephnt1.c // This example is from C for Scientists and Engineers #include
More informationFrom Java to C. Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides
From Java to C Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides 1 Outline Overview comparison of C and Java Good evening Preprocessor
More informationCSE 333 Midterm Exam 5/9/14 Sample Solution
Question 1. (20 points) C programming. Implement the C library function strncpy. The specification of srncpy is as follows: Copy characters (bytes) from src to dst until either a '\0' character is found
More informationmith College Computer Science CSC231 Bash Labs Week #10, 11, 12 Spring 2017 Introduction to C Dominique Thiébaut
mith College CSC231 Bash Labs Week #10, 11, 12 Spring 2017 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 4 Hours! D. Thiebaut Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to
More informationLinked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links
Linked-List Basic Examples A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links Accessed via a pointer to the first node of the list Subsequent
More informationSOFTWARE Ph.D. Qualifying Exam Spring Consider the following C program which consists of two function definitions including the main function.
(i) (5 pts.) SOFTWARE Ph.D. Qualifying Exam Spring 2018 Consider the following C program which consists of two function definitions including the main function. #include int g(int z) { int y
More informationP.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above
P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above
More informationLesson #8. Structures Linked Lists Command Line Arguments
Lesson #8 Structures Linked Lists Command Line Arguments Introduction to Structures Suppose we want to represent an atomic element. It contains multiple features that are of different types. So a single
More informationC Programming Language: C ADTs, 2d Dynamic Allocation. Math 230 Assembly Language Programming (Computer Organization) Thursday Jan 31, 2008
C Programming Language: C ADTs, 2d Dynamic Allocation Math 230 Assembly Language Programming (Computer Organization) Thursday Jan 31, 2008 Overview Row major format 1 and 2-d dynamic allocation struct
More informationadvanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef
today advanced data types (1) typedef. mon 23 sep 2002 homework #1 due today homework #2 out today quiz #1 next class 30-45 minutes long one page of notes topics: C advanced data types dynamic memory allocation
More informationMIDTERM EXAM. CS 217 October 28, Name: Precept: Honor Code: Score: Problem Score Max
MIDTERM EXAM CS 217 October 28, 1999 Name: Precept: Honor Code: Score: Problem Score Max 1 15 2 5 3 10 4 15 5 5 6 10 7 10 Total 70 1 1. Number Systems (a) Translate the following decimal numbers to binary,
More informationLecture 04 Introduction to pointers
Lecture 04 Introduction to pointers A pointer is an address in the memory. One of the unique advantages of using C is that it provides direct access to a memory location through its address. A variable
More informationPointers. Part VI. 1) Introduction. 2) Declaring Pointer Variables. 3) Using Pointers. 4) Pointer Arithmetic. 5) Pointers and Arrays
EE105: Software Engineering II Part 6 Pointers page 1 of 19 Part VI Pointers 1) Introduction 2) Declaring Pointer Variables 3) Using Pointers 4) Pointer Arithmetic 5) Pointers and Arrays 6) Pointers and
More informationLaboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information
Laboratory 2: Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information 3. Comment: a. name your program with extension.c b. use o option to specify
More informationEM108 Software Development for Engineers
EE108 Section 6 Pointers page 1 of 20 EM108 Software Development for Engineers Section 6 - Pointers 1) Introduction 2) Declaring Pointer Variables 3) Using Pointers 4) Pointer Arithmetic 5) Pointers and
More informationCOP 3223 Introduction to Programming with C - Study Union - Spring 2018
COP 3223 Introduction to Programming with C - Study Union - Spring 2018 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................
More informationAdvanced Pointer Topics
Advanced Pointer Topics Pointers to Pointers A pointer variable is a variable that takes some memory address as its value. Therefore, you can have another pointer pointing to it. int x; int * px; int **
More informationCS113: Lecture 5. Topics: Pointers. Pointers and Activation Records
CS113: Lecture 5 Topics: Pointers Pointers and Activation Records 1 From Last Time: A Useless Function #include void get_age( int age ); int age; get_age( age ); printf( "Your age is: %d\n",
More informationStructures. Basics of Structures (6.1) EECS l Now struct point is a valid type. l Defining struct variables: struct point { int x; int y; };
Structures EECS 2031 25 September 2017 1 Basics of Structures (6.1) struct point { int x; int y; keyword struct introduces a structure declaration. point: structure tag x, y: members The same member names
More informationECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.
ECE 264 Exam 2 6:30-7:30PM, March 9, 2011 I certify that I will not receive nor provide aid to any other student for this exam. Signature: You must sign here. Otherwise you will receive a 1-point penalty.
More informationPointers, Dynamic Data, and Reference Types
Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple
More informationRicardo Rocha. Department of Computer Science Faculty of Sciences University of Porto
Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Adapted from the slides Revisões sobre Programação em C, Sérgio Crisóstomo Compilation #include int main()
More informationC Programming Review CSC 4320/6320
C Programming Review CSC 4320/6320 Overview Introduction C program Structure Keywords & C Types Input & Output Arrays Functions Pointers Structures LinkedList Dynamic Memory Allocation Macro Compile &
More informationBit Manipulation in C
Bit Manipulation in C Bit Manipulation in C C provides six bitwise operators for bit manipulation. These operators act on integral operands (char, short, int and long) represented as a string of binary
More informationreturn return else return
compare0.c 1 // Compares two strings' addresses 4 #include 5 6 int main(void) 7 { 8 // get two strings 9 string s = get_string("s: "); 10 string t = get_string("t: "); 11 1 // compare strings'
More informationET156 Introduction to C Programming
ET156 Introduction to C Programming g Unit 22 C Language Elements, Input/output functions, ARITHMETIC EXPRESSIONS AND LIBRARY FUNCTIONS Instructor : Stan Kong Email : skong@itt tech.edutech.edu General
More informationmith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut
mith College CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 2 Hours D. Thiebaut Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to Assembly Unix Standard
More informationUnit 8. Structures and Unions. School of Science and Technology INTRODUCTION
INTRODUCTION Structures and Unions Unit 8 In the previous unit 7 we have studied about C functions and their declarations, definitions, initializations. Also we have learned importance of local and global
More informationFunctions in C C Programming and Software Tools. N.C. State Department of Computer Science
Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the
More informationCSC209H Lecture 4. Dan Zingaro. January 28, 2015
CSC209H Lecture 4 Dan Zingaro January 28, 2015 Strings (King Ch 13) String literals are enclosed in double quotes A string literal of n characters is represented as a n+1-character char array C adds a
More informationLanguage comparison. C has pointers. Java has references. C++ has pointers and references
Pointers CSE 2451 Language comparison C has pointers Java has references C++ has pointers and references Pointers Values of variables are stored in memory, at a particular location A location is identified
More informationChapter 19: Program Design. Chapter 19. Program Design. Copyright 2008 W. W. Norton & Company. All rights reserved.
Chapter 19 Program Design 1 Introduction Most full-featured programs are at least 100,000 lines long. Although C wasn t designed for writing large programs, many large programs have been written in C.
More informationC Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017
C Concepts - I/O Lecture 19 COP 3014 Fall 2017 November 29, 2017 C vs. C++: Some important differences C has been around since around 1970 (or before) C++ was based on the C language While C is not actually
More informationECE264 Fall 2013 Exam 2, October 24, 2013
ECE Fall 0 Exam, October, 0 If this is an on-line exam, you have 0 minutes to finish the exam. When the time limit is reached, the system will automatically close. If this is a paper exam, you have 0 minutes.
More informationFinal Intro to C Review
Final Exam Content: Final Intro to C Review - Pass by reference Functions - General Syntax - Structures - Recursion(maybe?) - Programming by nature is cumulative so any past material is up for grabs as
More informationAN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University
AN OVERVIEW OF C, PART 3 CSE 130: Introduction to Programming in C Stony Brook University FANCIER OUTPUT FORMATTING Recall that you can insert a text field width value into a printf() format specifier:
More informationMidterm Examination # 2 Wednesday, March 19, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:
Page 1 of 7 School of Computer Science 60-141-01 Introduction to Algorithms and Programming Winter 2014 Midterm Examination # 2 Wednesday, March 19, 2014 ANSWERS Duration of examination: 75 minutes STUDENT
More informationLesson 6.1: Structs. This declares a collection of two integer variables to denote the two coordinates of a point in a plane.
Lesson 6.1: Structs Programming in C Prof. Dr. Eike Best Dr. Elke Wilkeit October 12, 2002 1 struct point { 2 int x; 3 int y; 4 }; This declares a collection of two integer variables to denote the two
More informationCS1003: Intro to CS, Summer 2008
CS1003: Intro to CS, Summer 2008 Lab #07 Instructor: Arezu Moghadam arezu@cs.columbia.edu 6/25/2008 Recap Pointers Structures 1 Pointer Arithmetic (exercise) What do the following return? given > char
More informationJTSK Programming in C II C-Lab II. Lecture 3 & 4
JTSK-320112 Programming in C II C-Lab II Lecture 3 & 4 Xu (Owen) He Spring 2018 Slides modified from Dr. Kinga Lipskoch Planned Syllabus The C Preprocessor Bit Operations Pointers and Arrays (Dynamically
More informationDynamic memory. EECS 211 Winter 2019
Dynamic memory EECS 211 Winter 2019 2 Initial code setup $ cd eecs211 $ curl $URL211/lec/06dynamic.tgz tar zx $ cd 06dynamic 3 Oops! I made a mistake. In C, the declaration struct circle read_circle();
More informationelse return for return
addresses.c 1 // Prints two strings' addresses 4 #include 5 6 int main(void) 7 { 8 // Get two strings 9 string s = get_string("s: "); 10 string t = get_string("t: "); 11 1 // Print strings' addresses
More informationOutline. Briefly review the last class Pointers and Structs Memory allocation Linked lists
Outline Briefly review the last class Pointers and Structs Memory allocation Linked lists C Structures and Memory Allocation A struct is a data structure that comprises multiple types, each known as a
More informationNYU SCPS X Section 1 Unix System Calls. Fall 2004 Handout 8. Source code on the Web at mm64/x /src/doubly2.
Fall 2004 Handout 8 Source code on the Web at http://i5.nyu.edu/ mm64/x52.9232/src/doubly2.c 1 /* 2 Let the user type in positive numbers, not necessarily unique. Store them in 3 ascending order in a dynamically
More informationSelf-referential Structures and Linked List. Programming and Data Structure 1
Self-referential Structures and Linked List Programming and Data Structure 1 Linked List :: Basic Concepts A list refers to a set of items organized sequentially. An array is an example of a list. The
More informationPointers. Pointer Variables. Chapter 11. Pointer Variables. Pointer Variables. Pointer Variables. Declaring Pointer Variables
Chapter 11 Pointers The first step in understanding pointers is visualizing what they represent at the machine level. In most modern computers, main memory is divided into bytes, with each byte capable
More informationFinal C Details. CSE 333 Autumn 2018
Final C Details CSE 333 Autumn 2018 Instructor: Hal Perkins Teaching Assistants: Tarkan Al-Kazily Renshu Gu Trais McGaha Harshita Neti Thai Pham Forrest Timour Soumya Vasisht Yifan Xu Administriia Today:
More informationAssignment 6. Q1. Create a database of students using structures, where in each entry of the database will have the following fields:
Assignment 6 Q1. Create a database of students using structures, where in each entry of the database will have the following fields: 1. a name, which is a string with at most 128 characters 2. their marks
More informationmith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut
mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut dthiebaut@smithedu Outline A Few Words about HW 8 Finish the Input Port Lab! Revisiting Homework
More informationCompiling and Running a C Program in Unix
CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 95 ] Compiling and Running a C Program in Unix Simple scenario in which your program is in a single file: Suppose you want to name
More informationby: Lizawati, Norhidayah & Muhammad Noorazlan Shah Computer Engineering, FKEKK, UTeM
by: Lizawati, Norhidayah & Muhammad Noorazlan Shah Computer Engineering, FKEKK, UTeM At the end of this chapter, the students should be able to: understand and apply typedef understand and apply structure
More informationCS113: Lecture 9. Topics: Dynamic Allocation. Dynamic Data Structures
CS113: Lecture 9 Topics: Dynamic Allocation Dynamic Data Structures 1 What s wrong with this? char *big_array( char fill ) { char a[1000]; int i; for( i = 0; i < 1000; i++ ) a[i] = fill; return a; void
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationRecap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam
Multimedia Programming 2004 Lecture 2 Erwin M. Bakker Joachim Rijsdam Recap Learning C++ by example No groups: everybody should experience developing and programming in C++! Assignments will determine
More informationCSC231 C Tutorial Fall 2018 Introduction to C
mith College CSC231 C Tutorial Fall 2018 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 4 Installments! Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to Assembly Unix Standard
More informationCMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 13, SPRING 2013
CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 13, SPRING 2013 TOPICS TODAY Reminder: MIDTERM EXAM on THURSDAY Pointer Basics Pointers & Arrays Pointers & Strings Pointers & Structs
More informationPRINCIPLES OF OPERATING SYSTEMS
PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)
More informationC Overview Fall 2014 Jinkyu Jeong
C Overview Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 # for preprocessor Indicates where to look for printf() function.h file is a header file #include int main(void) { printf("hello, world!\n");
More informationDS Assignment I. 1. Set a pointer by name first and last to point to the first element and last element of the list respectively.
DS Assignment I 1 Suppose an integer array by name list is declared of size N (ex: #define N 10 int list[n]; ) Write C statements to achieve the following: 1 Set a pointer by name first and last to point
More information#include <stdio.h> int main() { char s[] = Hsjodi, *p; for (p = s + 5; p >= s; p--) --*p; puts(s); return 0;
1. Short answer questions: (a) Compare the typical contents of a module s header file to the contents of a module s implementation file. Which of these files defines the interface between a module and
More informationIntroduction to Computing Lecture 01: Introduction to C
Introduction to Computing Lecture 01: Introduction to C Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical&Electronics Engineering ozbek.nukhet@gmail.com Topics Introduction to C language
More informationDynamic Memory CMSC 104 Spring 2014, Section 02, Lecture 24 Jason Tang
Dynamic Memory CMSC 104 Spring 2014, Section 02, Lecture 24 Jason Tang Topics Memory Lifetime Dynamic Memory Allocation Dynamic Memory Deallocation Variable Lifetime (Review) Lifetime refers to when the
More informationAlgorithms & Programming. Midterm Examination # 2. Student Name: Student ID Number: Duration of examination:
School of Computer Science 60-141-01 Algorithms & Programming Winter 2007 Midterm Examination # 2 Wednesday, March 21, 2007 Student Name: First Name Family Name Student ID Number: Duration of examination:
More informationIn this session we will cover the following sub-topics: 1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.
In this session we will cover the following sub-topics: 1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.Semantic www.tenouk.com, 1/16 C IDENTIFIERS 1. Is a unique
More informationFunctions in C C Programming and Software Tools
Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the
More informationProgramming and Data Structures
Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()
More informationANSI C Reserved Words
Multimedia Programming 2004 Lecture 3 Erwin M. Bakker Joachim Rijsdam ANSI C Reserved Words auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, int,
More informationELEC 377 C Programming Tutorial. ELEC Operating Systems
ELE 377 Programming Tutorial Outline! Short Introduction! History & Memory Model of! ommon Errors I have seen over the years! Work through a linked list example on the board! - uses everything I talk about
More information