C Review. MaxMSP Developers Workshop Summer 2009 CNMAT
|
|
- Antonia Whitehead
- 5 years ago
- Views:
Transcription
1 C Review MaxMSP Developers Workshop Summer 2009 CNMAT
2 C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (*** IMPORTANT ***) Preprocessor directives, macros Compiling, linking, debugging
3 Syntax Code blocks in { } Every line ends with ; Whitespace is ignored Control order-of-evaluation for expressions with ( ) (i.e. just like in math) Strings are surrounded by Special compiler-stuff begins with # Comments start with // or surround with /*... */
4 Flow Control while: loop until a test is false for: run a start action, loop until a test is false, do some action between each iteration do: loop until a test is false with a minimum of one run switch: jump to a point in the program based on a value if, else: run some code if a test is true, otherwise do something else goto: jump immediately to a named location
5 Function Prototype int myfunc(int argc, char* argv); Return type: int Name of function: myfunc Input type(s): int, char*
6 The Main Function int main() { // do something here //... // all done! return 0; } main automatically executes when your program is loaded. when main returns the program is done (unless there are other threads still running)
7 Header Files #include <stdio.h> int main() { printf("hello World\n"); return 0; } Has the.h extension Contains a collection of function prototypes so the compiler knows what types a function takes and returns (e.g. what does printf do?)
8 Variables Every variable has a fixed type that cannot be changed. (static type) The number of bytes taken by a type is given by sizeof(). You can make up your own types by combining other types and declare them with typedef. Usually they are named like t_something
9 Global Variables int x; void add_to_x(int y) { x = x + y; }
10 Local Variables int sum_up_to(int x) { int s; int i; s = 0; for(i = 0; i <= x; i++) { s = s + i; } } return s;
11 Type Declarations A type declaration creates a variable of a defined type and gives it a name. Every named variable has to have a type declaration. Every named variable exists either on The Heap (global scope, lives forever) or The Stack (in a function, lives until the function returns).
12 Type Declarations int x; let x be of type int
13 Basic Types // Integer int x; // Float (real number with decimals) float f; // A float with extra accuracy (good to use) double d; // Many things of the same type int a, b, c, d; // A single letter char letter; // A bunch of letters (string) char* foo = foo ;
14 Expressions An expression is a bit of code that is evaluated The result of an expression is always a known type, called the return type The return type is determined by the compiler by analyzing the code
15 Assignment with = // = means assignment a = 4 * 6; // assignment can self-reference a = a + 5; // == tests if a is equal to 5 a == 5;
16 Expressions (6 * 7); the int that is 6 times 7
17 Typecasting You can force a return type to be transformed to another type by using a typecast. Unless the compiler knows how to interpret your typecast, the results may be unexpected. Avoid using typecasts whenever possible. C++ fixes the bad behavior of typecasts.
18 Expressions with Type Casting (float)(6 * 7); change the int that is 6 times 7 into a float
19 Assignment An expression can be assigned to a variable. The return type of the expression must match the declared type of the variable Assignment works on entire structures also.
20 Expressions int x; x = (6 * 7); let x be of type int. x gets the int that is 6 times 7.
21 Pointer to a Type There is a meta type that is a pointer to any defined type. This type can be declared using the * operator in a type declaration.
22 Declaring a Pointer to a Type int *x; let x be a pointer that when dereferenced is an int
23 Point of Confusion with * int *x; int* x; Both mean the same thing.
24 Pointer to an Unknown Type void *x; let x be a pointer that when dereferenced is an unknown thing
25 Address-of Address-of, &, is an operator that returns a pointer to whatever it is prefixed to.
26 Pointer to a Type int y; int *x; Note &y is an rvalue x = &y; let y be an int. let x be of type pointer-to-an-int. x gets the the address of y
27 Pointer Dereferencing If you have a pointer-to-type you can dereference the pointer to access the thing that it points to. The dereference operator is the * operator. The dereference operator can be used in a type declaration also... and it modifies the type.
28 Pointer Dereferencing int y; int *x; x = &y; *x = 42; let y be an int. let x be of a pointer that dereferences to an int. x gets the address of y. the int that is pointed-to by x gets 42.
29 Structures A collection of other types, packed together into a bigger type. Usually called t_something
30 Structures typedef struct { int a; int b; } t_twoints; define a type called t_twoints consisting of an int called a followed by an int called b...
31 Accessing Structure Elements t_twoints x; int y; x.a = 1; x.b = 1; member a in x gets 1 member b in x gets 2
32 Structure Assignment t_twoints x; t_twoints y; x.a = 1; x.b = 1; y = x member a in x gets 1 member b in x gets 2 y gets x
33 Pointer to a Structure int sum_twoints(t_twoints *y) { } let sum_twoints be a function that returns an int given a pointer-to a t_twoints called y
34 Pointer to a Structure int sum_twoints(t_twoints *y) { return y->a + y->b; } return the sum of a in the t_twoints pointed-to by y and b in the t_twoints pointed-to by y
35 Pointer to a Structure t_twoints x; int y; x.a = 1; x.b = 1; y = sum_twoints(&x); y gets the result of sum_twoints applied to the thing pointed-to by the address-of x
36 Dereferencing with Structures y->a is the same as (*y).a typedef struct twoints { int a; int b; } t_twoints; t_twoints y; y.a = 42; y.b = 43; t_twoints* y; y = (t_twoints*)malloc(sizeof(t_twoints)); y->a = 42; y->b = 43;
37 Memory Address Contents
38 Memory containing a 4-byte integer Address Contents st byte 2nd byte 3rd byte 4th byte sizeof(int) == 4 byte means number from 0-255
39 What is a pointer really? A reference is the memory address of a thing stored in memory. A reference cannot be changed. A pointer is a reference stored in memory. A pointer can be changed to the value of a reference to another thing (or nothing, also called a null pointer )
40 Memory Address Contents int *x; x = 5;
41 De-referencing * is the the de-referencing operator It is a unary operator It appears before the thing being dereferenced. (*x) is the value of the thing that x points to.
42 Memory Address Contents int *x; x = 5; *x = 42;
43 References & gets the address of something. Its also a unary prefix operator.
44 Setting a Pointer to a Thing Address Contents x int y; int *x; y 42 x = &y; *x = 42;
45 Huh? int y1; int y2; int *x; x = &y1; &y2 = x; // OK // Compiler error, // &y1 is not an lvalue
46 Pointer Arithmetic Suppose two things of the same type are located at sequential positions in memory: Let x point to the first one. x + 1 points to the second one.
47 Pointer Arithmetic int y1; int y2; int *x; x = &y1; *x = 42; *(x+1) = 43;
48 Pointer Incrementing int y1; int y2; int *x; x = &y1; *x = 42; x++; *x = 43;
49 Pointer types The actual memory address of x + 1 depends on the sizeof the pointed-to-type So, the compiler needs you to say what sort of thing is being pointed-to so it can figure this out. We can also use this to make arrays of things.
50 Pointers vs References They are the same thing, but... You can dereference a pointer You can dereference a reference You can assign an reference to a pointer You can assign a pointer to a pointer (or, increment it, decrement it, etc) You cannot assign anything to a reference
51 Arrays Lots of things of the same type The length of an array is fixed. It cannot be changed. Ever. In spite of this fact, the program has no idea how big your array is, and will do stupid things (like crashing) if you attempt to read or write to positions beyond the end of the array.
52 Array Indexing int y[2]; y[0] = 42; y[1] = 43;
53 Array Indexing Equivalent in Pointers int y[2]; *(y+0) = 42; *(y+1) = 43;
54 Even more Confusing Stuff int y[2]; int *x; x = &(y[0]); *x = 42; x = &(y[1]); *x = 43; y[0] dereferences the first element of y. Then we get a reference using &, assign it to x, dereference x, and assign the contents of that memory slot to the number 42.
55 Array Iterators Address Contents x int y[2]; int *x; y 42 x = y; *x = 42;
56 Array Iterators Address Contents x int y[2]; int *x; x = y; *x = 42; y x++; *x = 43;
57 2D Arrays and Pointer to a Pointer Address Contents x int y[2][2]; int **x; x = y; **x = 42; y 42
58 Where Memory Comes From The Heap: Where globally allocated variables live Automatically reclaimed when program exits Where dynamically allocated memory comes from (using malloc or equivalent) Manually reclaimed using free (if you forget then its a memory leak )
59 Where Memory Comes From The Stack Where local variables live (declared in the scope of a function) Automatically reclaimed when the function returns
60 Dynamic Allocation void *malloc(size_t size); int *y; y = (int*)malloc(sizeof(int) * 2); y[0] = 42; y[1] = 43; free(y); Casting a pointer to a known type!
61 Dynamic Allocation, Notes malloc() is a system call Usually malloc is very fast, but it might take a long time to return (e.g. when swapping to disk is necessary). malloc could return NULL if it fails to obtain the requested number of bytes.
62 Preprocessor Directives #include somefile.h #define FOOBAR 1 #ifdef, #endif, #ifndef, #assert...
63 Macros Macros are ALLCAPS by convention, but not necessarily so. #define FOOBAR 3 now FOOBAR is replaced with its definition everywhere in the code. Macros can be sort of like functions #define FOOBAR(x) (x + 3) This should only be used when absolutely necessary (try use C99 + inline instead)
64 Compilation Explained Source Code (.c and.h files...) Preprocessor Compiler Object files (.o) Libraries Linker Executable or Library
65 Debugging Compilation: Tips Bad executable or Cannot load bundle executable The final product is messed up (bad meta data, unsupported processor target, etc)
66 Debugging Compilation: Tips Unresolved symbol foobar You probably used a function, foobar, from a library or another object file, but that library wasnʼt present during the linking stage.
67 Debugging Compilation: Tips Syntax error line XXX Compiler canʼt understand what you are doing. Look for the problem near the error with the LOWEST line number (many of the subsequent errors are probably bogus).
68 Debugging Compilation: Tips Syntax error line XXX but you really, really, really canʼt see anything wrong. Are you using a MACRO???
69 Debugging Compilation: Tips Cannot find file ʻfoobar.hʼ You have included a file, e.g. #include foobar.h But that file isnʼt in the current directory, and its not in the include file search path for the compiler. (-I) Similar problem but the missing file is a library Check library search path (-l)
70 Compiler Options Optimization level: -O1: some optimization -ffast-math: do floating point math fast, but might be less accurate (also in -O3). Target Platform -march=(...) what CPU instruction set do you want to support? Options vary greatly by compiler...
71 SEGFAULT Virtual memory means that addresses do not point directly to physical memory. Protected memory means the operating system knows which addresses are valid for your program ( segment ). If you attempt to use an invalid address then you get a segmentation fault.
72 SEGFAULT: Typical causes Attempting to dereference a pointer that hasnʼt been initialized Attempting to access item in an array that is past the end of the array Trying to use a pointer after its memory has been reclaimed (via free or return)
73 More Info man pages Various books (amazon, oʼreilly, etc)
CS 31: Intro to Systems Pointers and Memory. Kevin Webb Swarthmore College October 2, 2018
CS 31: Intro to Systems Pointers and Memory Kevin Webb Swarthmore College October 2, 2018 Overview How to reference the location of a variable in memory Where variables are placed in memory How to make
More informationCSci 4061 Introduction to Operating Systems. Programs in C/Unix
CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,
More informationCS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor
CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static
More informationCS 31: Intro to Systems Pointers and Memory. Martin Gagne Swarthmore College February 16, 2016
CS 31: Intro to Systems Pointers and Memory Martin Gagne Swarthmore College February 16, 2016 So we declared a pointer How do we make it point to something? 1. Assign it the address of an existing variable
More informationCSCI 171 Chapter Outlines
Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures
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 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 informationC Introduction. Comparison w/ Java, Memory Model, and Pointers
CS 261 Fall 2018 Mike Lam, Professor C Introduction Comparison w/ Java, Memory Model, and Pointers Please go to socrative.com on your phone or laptop, choose student login and join room LAMJMU The C Language
More informationLectures 5-6: Introduction to C
Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most
More informationC Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,
More informationLectures 5-6: Introduction to C
Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most
More informationThe C Programming Language Guide for the Robot Course work Module
The C Programming Language Guide for the Robot Course work Module Eric Peasley 2018 v6.4 1 2 Table of Contents Variables...5 Assignments...6 Entering Numbers...6 Operators...7 Arithmetic Operators...7
More informationSYSC 2006 C Winter 2012
SYSC 2006 C Winter 2012 Pointers and Arrays Copyright D. Bailey, Systems and Computer Engineering, Carleton University updated Sept. 21, 2011, Oct.18, 2011,Oct. 28, 2011, Feb. 25, 2011 Memory Organization
More informationCSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2017 Lecture 8 C: Miscellanea Control, Declarations, Preprocessor, printf/scanf 1 The story so far The low-level execution model of a process (one
More informationQUIZ. What are 3 differences between C and C++ const variables?
QUIZ What are 3 differences between C and C++ const variables? Solution QUIZ Source: http://stackoverflow.com/questions/17349387/scope-of-macros-in-c Solution The C/C++ preprocessor substitutes mechanically,
More informationB.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University
Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are
More informationReview of the C Programming Language for Principles of Operating Systems
Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights
More informationMotivation was to facilitate development of systems software, especially OS development.
A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.
More informationChapter IV Introduction to C for Java programmers
Chapter IV Introduction to C for Java programmers Now that we have seen the native instructions that a processor can execute, we will temporarily take a step up on the abstraction ladder and learn the
More informationA Fast Review of C Essentials Part I
A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types
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 informationEL6483: Brief Overview of C Programming Language
EL6483: Brief Overview of C Programming Language EL6483 Spring 2016 EL6483 EL6483: Brief Overview of C Programming Language Spring 2016 1 / 30 Preprocessor macros, Syntax for comments Macro definitions
More informationRule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.
Chapter 9: Rules Chapter 1:Style and Program Organization Rule 1-1: Organize programs for readability, just as you would expect an author to organize a book. Rule 1-2: Divide each module up into a public
More informationReview of the C Programming Language
Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the
More informationCS 11 C track: lecture 5
CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap Pointers (from last week) Address: location where data stored
More informationCS 61C: Great Ideas in Computer Architecture. C Arrays, Strings, More Pointers
CS 61C: Great Ideas in Computer Architecture C Arrays, Strings, More Pointers Instructor: Justin Hsia 6/20/2012 Summer 2012 Lecture #3 1 Review of Last Lecture C Basics Variables, Functions, Flow Control,
More informationEMBEDDED SYSTEMS PROGRAMMING Language Basics
EMBEDDED SYSTEMS PROGRAMMING 2014-15 Language Basics (PROGRAMMING) LANGUAGES "The tower of Babel" by Pieter Bruegel the Elder Kunsthistorisches Museum, Vienna ABOUT THE LANGUAGES C (1972) Designed to replace
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 information0x0d2C May your signals all trap May your references be bounded All memory aligned Floats to ints round. remember...
Types Page 1 "ode to C" Monday, September 18, 2006 4:09 PM 0x0d2C ------ May your signals all trap May your references be bounded All memory aligned Floats to ints round remember... Non -zero is true ++
More informationEL2310 Scientific Programming
Lecture 7: Introduction to C (pronobis@kth.se) Overview Overview Lecture 7: Introduction to C Wrap Up Basic Datatypes and printf Branching and Loops in C Constant values Wrap Up Lecture 7: Introduction
More informationFirst of all, it is a variable, just like other variables you studied
Pointers: Basics 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 address (rather than the value)
More informationMemory and Addresses. Pointers in C. Memory is just a sequence of byte-sized storage devices.
Memory and Addresses Memory is just a sequence of byte-sized storage devices. 1 The bytes are assigned numeric addresses, starting with zero, just like the indexing of the cells of an array. It is the
More informationBLM2031 Structured Programming. Zeyneb KURT
BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help
More informationG52CPP C++ Programming Lecture 6. Dr Jason Atkin
G52CPP C++ Programming Lecture 6 Dr Jason Atkin 1 Last lecture The Stack Lifetime of local variables Global variables Static local variables const (briefly) 2 Visibility is different from lifetime Just
More informationTutorial 1: Introduction to C Computer Architecture and Systems Programming ( )
Systems Group Department of Computer Science ETH Zürich Tutorial 1: Introduction to C Computer Architecture and Systems Programming (252-0061-00) Herbstsemester 2012 Goal Quick introduction to C Enough
More informationQuiz 0 Review Session. October 13th, 2014
Quiz 0 Review Session October 13th, 2014 Topics (non-exhaustive) Binary. ASCII. Algorithms. Pseudocode. Source code. Compiler. Object code. Scratch. Statements. Boolean expressions. Conditions. Loops.
More information377 Student Guide to C++
377 Student Guide to C++ c Mark Corner January 21, 2004 1 Introduction In this course you will be using the C++ language to complete several programming assignments. Up to this point we have only provided
More informationMotivation was to facilitate development of systems software, especially OS development.
A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.
More informationBasic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island
Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types
More informationProgramming in C - Part 2
Programming in C - Part 2 CPSC 457 Mohammad Reza Zakerinasab May 11, 2016 These slides are forked from slides created by Mike Clark Where to find these slides and related source code? http://goo.gl/k1qixb
More informationPointer Basics. Lecture 13 COP 3014 Spring March 28, 2018
Pointer Basics Lecture 13 COP 3014 Spring 2018 March 28, 2018 What is a Pointer? A pointer is a variable that stores a memory address. Pointers are used to store the addresses of other variables or memory
More informationFundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University
Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler
More informationQUIZ. Source:
QUIZ Source: http://stackoverflow.com/questions/17349387/scope-of-macros-in-c Ch. 4: Data Abstraction The only way to get massive increases in productivity is to leverage off other people s code. That
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 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 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 informationECE264 Spring 2013 Final Exam, April 30, 2013
ECE264 Spring 2013 Final Exam, April 30, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing
More informationVariables and literals
Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of
More informationTechnical Questions. Q 1) What are the key features in C programming language?
Technical Questions Q 1) What are the key features in C programming language? Portability Platform independent language. Modularity Possibility to break down large programs into small modules. Flexibility
More informationEL2310 Scientific Programming
Lecture 11: Structures and Memory (yaseminb@kth.se) Overview Overview Lecture 11: Structures and Memory Structures Continued Memory Allocation Lecture 11: Structures and Memory Structures Continued Memory
More informationIMPORTANT QUESTIONS IN C FOR THE INTERVIEW
IMPORTANT QUESTIONS IN C FOR THE INTERVIEW 1. What is a header file? Header file is a simple text file which contains prototypes of all in-built functions, predefined variables and symbolic constants.
More informationLecture 03 Bits, Bytes and Data Types
Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics
More informationDecision Making -Branching. Class Incharge: S. Sasirekha
Decision Making -Branching Class Incharge: S. Sasirekha Branching The C language programs presented until now follows a sequential form of execution of statements. Many times it is required to alter the
More informationAdministrivia. Introduction to Computer Systems. Pointers, cont. Pointer example, again POINTERS. Project 2 posted, due October 6
CMSC 313 Introduction to Computer Systems Lecture 8 Pointers, cont. Alan Sussman als@cs.umd.edu Administrivia Project 2 posted, due October 6 public tests s posted Quiz on Wed. in discussion up to pointers
More informationDeep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems
Deep C Multifile projects Getting it running Data types Typecasting Memory management Pointers Fabián E. Bustamante, Fall 2004 Multifile Projects Give your project a structure Modularized design Reuse
More informationDynamic memory allocation (malloc)
1 Plan for today Quick review of previous lecture Array of pointers Command line arguments Dynamic memory allocation (malloc) Structures (Ch 6) Input and Output (Ch 7) 1 Pointers K&R Ch 5 Basics: Declaration
More informationby Pearson Education, Inc. All Rights Reserved.
Let s improve the bubble sort program of Fig. 6.15 to use two functions bubblesort and swap. Function bubblesort sorts the array. It calls function swap (line 51) to exchange the array elements array[j]
More informationCprE 288 Introduction to Embedded Systems Exam 1 Review. 1
CprE 288 Introduction to Embedded Systems Exam 1 Review http://class.ece.iastate.edu/cpre288 1 Overview of Today s Lecture Announcements Exam 1 Review http://class.ece.iastate.edu/cpre288 2 Announcements
More informationIntroduction to C. Robert Escriva. Cornell CS 4411, August 30, Geared toward programmers
Introduction to C Geared toward programmers Robert Escriva Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Cornell CS 4411, August 30, 2010 1 Why C? 2 A Quick Example 3 Programmer s Responsibilities
More informationMore about BOOLEAN issues
More about BOOLEAN issues Every boolean test is an implicit comparison against zero (0). However, zero is not a simple concept. It represents: the integer zero for all integral types the floating point
More informationPrograms in memory. The layout of memory is roughly:
Memory 1 Programs in memory 2 The layout of memory is roughly: Virtual memory means that memory is allocated in pages or segments, accessed as if adjacent - the platform looks after this, so your program
More informationIntroduction to C: Pointers
Introduction to C: Pointers Nils Moschüring PhD Student (LMU) Nils Moschüring PhD Student (LMU), Introduction to C: Pointers 1 1 Introduction 2 Pointers Basics Useful: Function
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 informationCS 61c: Great Ideas in Computer Architecture
Introduction to C, Pointers June 24, 2014 Review of Last Lecture Six Great Ideas in Computer Architecture Number Representation Bits can represent anything! n bits can represent up to 2 n things Unsigned,
More informationECEN 449 Microprocessor System Design. Review of C Programming. Texas A&M University
ECEN 449 Microprocessor System Design Review of C Programming 1 Objectives of this Lecture Unit Review C programming basics Refresh programming skills 2 Basic C program structure # include main()
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationCS107 Handout 08 Spring 2007 April 9, 2007 The Ins and Outs of C Arrays
CS107 Handout 08 Spring 2007 April 9, 2007 The Ins and Outs of C Arrays C Arrays This handout was written by Nick Parlante and Julie Zelenski. As you recall, a C array is formed by laying out all the elements
More informationCSCI 350: Getting Started with C Written by: Stephen Tsung-Han Sher June 12, 2016
CSCI 350: Getting Started with C Written by: Stephen Tsung-Han Sher June 12, 2016 Introduction As you have been informed, your work with Pintos will be almost exclusively with C. Since you have taken CSCI-103
More informationa data type is Types
Pointers Class 2 a data type is Types Types a data type is a set of values a set of operations defined on those values in C++ (and most languages) there are two flavors of types primitive or fundamental
More informationModel Viva Questions for Programming in C lab
Model Viva Questions for Programming in C lab Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart is a diagram that shows a continuous
More informationHigh-performance computing and programming Intro to C on Unix/Linux. Uppsala universitet
High-performance computing and programming Intro to C on Unix/Linux IT Uppsala universitet What is C? An old imperative language that remains rooted close to the hardware C is relatively small and easy
More informationQUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:
QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the
More informationQuiz 0 Answer Key. Answers other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d. True or False.
Quiz 0 Answer Key Answers other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d True or False. 6. T or F 7. T 8. F 9. T 10. T or F Itching for Week 0? 11. 00011001 + 00011001
More informationUnderstanding Pointers
Division of Mathematics and Computer Science Maryville College Pointers and Addresses Memory is organized into a big array. Every data item occupies one or more cells. A pointer stores an address. A pointer
More informationAbout Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals
More informationHave examined process Creating program Have developed program Written in C Source code
Preprocessing, Compiling, Assembling, and Linking Introduction In this lesson will examine Architecture of C program Introduce C preprocessor and preprocessor directives How to use preprocessor s directives
More informationC++ Tutorial AM 225. Dan Fortunato
C++ Tutorial AM 225 Dan Fortunato Anatomy of a C++ program A program begins execution in the main() function, which is called automatically when the program is run. Code from external libraries can be
More informationAgenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011
CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduction to C (Part II) Instructors: Randy H. Katz David A. Patterson http://inst.eecs.berkeley.edu/~cs61c/sp11 Spring 2011 -- Lecture
More informationC++ Programming Chapter 7 Pointers
C++ Programming Chapter 7 Pointers Yih-Peng Chiou Room 617, BL Building (02) 3366-3603 ypchiou@cc.ee.ntu.edu.tw Photonic Modeling and Design Lab. Graduate Institute of Photonics and Optoelectronics & Department
More information3/22/2016. Pointer Basics. What is a pointer? C Language III. CMSC 313 Sections 01, 02. pointer = memory address + type
Pointer Basics What is a pointer? pointer = memory address + type C Language III CMSC 313 Sections 01, 02 A pointer can contain the memory address of any variable type A primitive (int, char, float) An
More informationArrays and Pointers in C & C++
Arrays and Pointers in C & C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++,
More informationch = argv[i][++j]; /* why does ++j but j++ does not? */
CMPS 12M Introduction to Data Structures Lab Lab Assignment 4 The purpose of this lab assignment is to get more practice programming in C, including the character functions in the library ctype.h, and
More informationCS61C : Machine Structures
inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 4 Introduction to C (pt 2) 2014-09-08!!!Senior Lecturer SOE Dan Garcia!!!www.cs.berkeley.edu/~ddgarcia! C most popular! TIOBE programming
More informationDesign and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso
Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso Why C? Test on 21 Android Devices with 32-bits and 64-bits processors and different versions
More informationC Programming SYLLABUS COVERAGE SYLLABUS IN DETAILS
C Programming C SYLLABUS COVERAGE Introduction to Programming Fundamentals in C Operators and Expressions Data types Input-Output Library Functions Control statements Function Storage class Pointer Pointer
More informationHeap Arrays and Linked Lists. Steven R. Bagley
Heap Arrays and Linked Lists Steven R. Bagley Recap Data is stored in variables Can be accessed by the variable name Or in an array, accessed by name and index Variables and arrays have a type Create our
More informationA brief introduction to C programming for Java programmers
A brief introduction to C programming for Java programmers Sven Gestegård Robertz September 2017 There are many similarities between Java and C. The syntax in Java is basically
More informationMemory Corruption 101 From Primitives to Exploit
Memory Corruption 101 From Primitives to Exploit Created by Nick Walker @ MWR Infosecurity / @tel0seh What is it? A result of Undefined Behaviour Undefined Behaviour A result of executing computer code
More information10/20/2015. Midterm Topic Review. Pointer Basics. C Language III. CMSC 313 Sections 01, 02. Adapted from Richard Chang, CMSC 313 Spring 2013
Midterm Topic Review Pointer Basics C Language III CMSC 313 Sections 01, 02 1 What is a pointer? Why Pointers? Pointer Caution pointer = memory address + type A pointer can contain the memory address of
More informationArrays and Pointers. CSE 2031 Fall November 11, 2013
Arrays and Pointers CSE 2031 Fall 2013 November 11, 2013 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 Arrays: Example
More informationIntroduction to C. Sean Ogden. Cornell CS 4411, August 30, Geared toward programmers
Introduction to C Geared toward programmers Sean Ogden Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Robert Escriva Zhiyuan Teo Ayush Dubey Cornell CS 4411, August 30, 2013 Administrative Information
More informationIntroduction to C. Ayush Dubey. Cornell CS 4411, August 31, Geared toward programmers
Introduction to C Geared toward programmers Ayush Dubey Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Robert Escriva Zhiyuan Teo Cornell CS 4411, August 31, 2012 Administrative Information Outline
More informationECE 15B COMPUTER ORGANIZATION
ECE 15B COMPUTER ORGANIZATION Lecture 13 Strings, Lists & Stacks Announcements HW #3 Due next Friday, May 15 at 5:00 PM in HFH Project #2 Due May 29 at 5:00 PM Project #3 Assigned next Thursday, May 19
More informationA Quick Introduction to C Programming
A Quick Introduction to C Programming 1 C Syntax and Hello World What do the < > mean? #include inserts another file..h files are called header files. They contain stuff needed to interface to libraries
More informationDynamic memory allocation
Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes
More informationLecture 05 I/O statements Printf, Scanf Simple statements, Compound statements
Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple
More informationCMPE-013/L. Introduction to C Programming
CMPE-013/L Introduction to C Programming Bryant Wenborg Mairs Spring 2014 What we will cover in 13/L Embedded C on a microcontroller Specific issues with microcontrollers Peripheral usage Reading documentation
More informationHeap Arrays. Steven R. Bagley
Heap Arrays Steven R. Bagley Recap Data is stored in variables Can be accessed by the variable name Or in an array, accessed by name and index a[42] = 35; Variables and arrays have a type int, char, double,
More informationWhat the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.
C Flow Control David Chisnall February 1, 2011 Outline What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope Disclaimer! These slides contain a lot of
More informationC OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed
C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages
More information