Direct Memory Access. Lecture 2 Pointer Revision Command Line Arguments. What happens when we use pointers. Same again with pictures
|
|
- Barnaby Lindsey
- 5 years ago
- Views:
Transcription
1 Lecture 2 Pointer Revision Command Line Arguments Direct Memory Access C/C++ allows the programmer to obtain the value of the memory address where a variable lives. To do this we need to use a special variable type called a pointer. Pointers allow us to store the value of the memory address for a specific type of variable. To declare a variable as a pointer to a variable we use the * as follows 1 int i; 2 int *ptri; What happens when we use pointers Normally a variable directly contains a specific value A pointer contains the (memory) address of a variable that contains a specified value A variable name directly references a value and a pointer indirectly references a value Referencing a value through a pointer is called indirection Same again with pictures int *countptr int count 4 int count 4 count directly references a variable whose value is 4 countptr indirectly references a variable whose value is 4.
2 Simple Example What did that code do? 2 #include <cstdlib> 3 4 int main(void) 5 { 6 int i; 7 int *ptri; 8 i=5; 9 std::cout <<"I given the value 5 directly i="<<i<<std::endl; 10 ptri=&i; // ptri now points to i 11 *ptri=10; 12 std::cout <<"Now using the pointer ptri now equals "<<i <<std::endl; 13 std::cout <<"ptri = "<<ptri<<" *ptri = "<<*ptri<<std::endl; 14 return EXIT_SUCCESS; 15 } Firstly two variables are declared i a normal integer and *ptri which is a pointer The first assignment i=5 directly assigned i with the value 5. The second assignment ptri=&i says store the address of the variable i into the variable ptri The final assignment *ptri=10; tells the program to put the value 10 into the memory address pointed to by ptri confused?... Lets look at some pictures With Pictures With Pictures ptri=&i; *ptri=10; 0x100 0x100 i 0x102 i 10 0x102 0x104 0x104 ptri 0x102 0x106 ptri 0x102 0x106 0x108 0x108 0x10A 0x10A
3 char **data; Can any determine what char **data is representing? char ** It s a pointer to a pointer of char data 0x10 Some Text\n Think of it as char[][] *data 0x22 more data\n char **data 0x10 0x22 0xff 0x9f 0x1ff 0x2ff 0x3ff 0xff Text here\n 0x9f and here\n 0x1ff must be terminated by\n Memory 0x2ff and here \n 0x3ff \n Memory pass by value 1 int PassByValue(int a) 2 { 3 return a+10; 4 } Consider the function above When passing by value a temporary copy of the variable is made in memory taking up space and Once control returns to the calling procedure any changes to the variable will not be recognised, and you will still have the original variable. pass by Reference 1 void PassByRef(int &a) 2 { 3 a+=10; 4 } This essentially passes a pointer, but not the same kind of pointer you would get when using int *a; That is why it is called by reference, since that is what you have, a now acts as if it were the parameter just like in the by value way, but any changes affect the original variable passed in.
4 2 #include <cstdlib> 3 4 int PassByValue(int a); 5 void PassByRef(int &a); int main(void) 9 { 10 int value=10; std::cout<<passbyvalue(value)<<std::endl; 13 std::cout<<"value is "<<value<<std::endl; 14 PassByRef(value); 15 std::cout<<"value = "<<value<<std::endl; return EXIT_SUCCESS; 18 } int PassByValue(int a) 21 { 22 return a+10; 23 } void PassByRef(int &a) 26 { 27 a+=10; 28 } const In the original C++ design const was called readonly We shall see later in the year this is very useful when passing objects by reference As we can mark things as not being able to be modified but still having the advantage of pass by reference. This is a compile time check so no overhead in execution is encountered when doing this. We will be looking at this in more depth later in the course 2 #include <cstdlib> 3 4 void ConstParam(const int &a) 5 { 6 a+=10; 7 } int main() 11 { 12 int value=10; 13 ConstParam(value); return EXIT_SUCCESS; 16 } 1 g++ const.cpp 2 const.cpp: In function 'void ConstParam(const int&)': 3 const.cpp:6: error: assignment of read-only reference 'a' Command Line arguments When a program is executed from a command line it may be passed different parameters as arguments to the program. Many examples of this may be seen in the Unix operating system with standard commands. For example ls may be used on it's own or with different flags such as ls -al where the -al is a command line argument.
5 main() The main function is the entry point in any C / C++ program and may be declared in a number of ways as shown below 1 int main() 2 int main(int argc, char *argv[]) 3 int main(int argc, char **argv) The first version returns an integer value when the program has exited. Next two versions are the same main has two parameters, int argc and char *argv[]. These are the only parameters that main in allowed and are used in the following ways int argc is the argument count and passes the number of arguments passed at the command line. char * argv is a pointer to a list of command line arguments which may be accessed as if they were a series of strings. sample program 2 #include <cstdlib> 3 4 int main(int argc, char **argv) 5 { 6 for (int i=0; i<argc; ++i) 7 std::cout <<"argument #"<<i<<" value "<<argv[i]<<"\n"; 8 9 return EXIT_SUCCESS; 10 } 1 argument #0 value a.out 2 argument #1 value -a 3 argument #2 value -b 4 argument #3 value test 5 argument #4 value 1 6 argument #5 value 2 7 argument #6 value 3 Simple Example II You will notice that the first argument (argv[0]) prints out a.out. This is because the whole of the command line typed is passed into the program. When the program is executed the command line is parsed and each space separated command is placed into each argv array element. Finally the size of the argv array is placed into argc. Parsing Command Line args This process is not automatic, you have to decide upon the argument types and how they affect the program This is part of the program design process It is usually the first thing you do after main.
6 Exercise We need a program that can respond to the following flags -h :- print out help and exit -a :- add the character to the message string -d put program in debug mode How would we approach the design of this program? 1 #include <stdlib.h> 2 #include <iostream> 3 #include <string> 4 // cstring for c strcmp 5 #include <cstring> int main (int argc, char * argv[]) 9 { 10 int argcount=1; /* argv 1 is the first parameter */ 11 bool Debug=false; 12 std::string message; 13 while(argcount < argc ) 14 { 15 if(strcmp(argv[argcount],"-h") == 0) 16 { 17 std::cout << "You asked for Help \n Now exiting\n"; 18 exit(exit_failure); 19 } 20 else if(strcmp(argv[argcount],"-a") == 0) 21 { 22 std::cout <<"Adding "<<argv[++argcount]<<std::endl; 23 message +=argv[argcount]; 24 message +=" "; 25 ++argcount; 26 } 27 else if(strcmp(argv[argcount],"-d") == 0) 28 { 29 ++argcount; 30 Debug=true; 31 } 32 else 33 { 34 std::cout <<"unknown argument #"<<argcount++<<std::endl; 35 } 36 } // end of parse args std::cout <<"Ending program Debug mode "<<Debug<<std::endl; 39 std::cout <<"Message is \""<<message<<"\"\n"; 40 return EXIT_SUCCESS; 41 } 42 1 a.out -a hello -a main -a input -d 1 Adding hello 2 Adding main 3 Adding input 4 Ending program Debug mode 1 5 Message is "hello main input " C++ strings In the previous example we used the C++ string data type This is a class that allows use to store text data It has many built in functions to allow us to do comparisons and manipulations of text data In this example we use the += function to concatenate the strings together. We will see later that we can do comparisons using the == functions as well bool data type We also use the bool data type to represent boolean values it can be assigned to either true or false It is preferable to use this for any truth data values
7 getopt The simplest way to handle command line options is the getopt C library function. It is part of the standard unix library and versions are available for shell scripts and Python 1 #include <unistd.h> 2 3 extern char *optarg; 4 extern int optind; 5 extern int optopt; 6 extern int opterr; 7 extern int optreset; 8 9 int getopt(int argc, char * const argv[], const char *optstring); for more info type man 3 getopt in the console 2 #include <cstring> 3 #include <unistd.h> // for get opt 4 5 // a list of the arguments to look for 6 const char ARGUMENTS[]="vdhf:ab"; 7 8 int main (int argc, char * argv[]) 9 { 10 // the character returned from the getopt function 11 char c; 12 bool Debug=false; while( (c=getopt(argc,argv,arguments))!=eof) 15 { 16 switch(c) // which option has been chosen 17 { 18 case 'h' : // -h 19 std::cout<< "You asked for Help \n Now exiting\n"; 20 exit(exit_failure); 21 break; case 'f' : // -f 24 std::cout <<"Passing the File flag the filename is "<<optarg<<std::endl; 25 break; case 'd' : 28 Debugˆ=true; 29 break; 30 case 'a' : 31 std::cout <<"-a called\n"; 32 break; case 'b' : 35 std::cout <<"-b called\n"; 36 break; case '?' : // unknown option report this and exit 39 std::cout<<"unknown argument "<<optopt<<std::endl; 40 std::cout<<"valid arguments are -d -h -f [name]\n"; 41 std::cout<<"will now exit\n"; 42 exit(exit_failure); 43 break; }// end switch 46 } // end of parse args std::cout << "Ending program Debug mode = "<<Debug<<std::endl; return EXIT_SUCCESS; 51 } Environment Variables Environment List As well as command line arguments every C / C++ program is also passed an environment list. Like the argument list. the environment list is an array of character pointers, with each pointer containing the address of a null terminated C string. The address of the array of pointers is contained in the global variable environ defined as environment pointer environ: environment list NULL environment strings HOME=/home/jmacey\0 PATH=:/bin:/usr/bin\0 SHELL=/usr/bin/bash\0 USER=macey\0 LOGNAME=macey\0 1 extern char **environ;
8 getenv 2 #include <unistd.h> 3 #include <cstdlib> 4 5 int main(int argc, char *argv[] ) 6 { 7 char *Env; 8 if(argc <= 1) 9 { 10 std::cerr<<"usage : env VARIABLE\n"; 11 exit(exit_failure); 12 } 13 Env=getenv(argv[1]); if(env!=null) 16 std::cout<<argv[1]<<"="<<env<<std::endl; 17 else 18 std::cout<<"variable "<<argv[1]<<" does not exist\n"; 19 return EXIT_SUCCESS; }
Dynamic 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 5 Files and Streams
Lecture 5 Files and Streams Introduction C programs can store results & information permanently on disk using file handling functions These functions let you write either text or binary data to a file,
More informationIntroduction. Lecture 5 Files and Streams FILE * FILE *
Introduction Lecture Files and Streams C programs can store results & information permanently on disk using file handling functions These functions let you write either text or binary data to a file, and
More informationde facto standard C library Contains a bunch of header files and APIs to do various tasks
CSE333 SECTION 6 GNU C Library de facto standard C library Contains a bunch of header files and APIs to do various tasks Don t need to memorize everything Do need to know what if there s an API that can
More informationC-String Library Functions
Strings Class 34 C-String Library Functions there are several useful functions in the cstring library strlen: the number of characters before the \0 strncat: concatenate two strings together strncpy: overwrite
More informationRecitation: C Review. TA s 20 Feb 2017
15-213 Recitation: C Review TA s 20 Feb 2017 Agenda Logistics Attack Lab Conclusion C Assessment C Programming Style C Exercise Cache Lab Overview Appendix: Valgrind Clang / LLVM Cache Structure Logistics
More informationCS 220: Introduction to Parallel Computing. Input/Output. Lecture 7
CS 220: Introduction to Parallel Computing Input/Output Lecture 7 Input/Output Most useful programs will provide some type of input or output Thus far, we ve prompted the user to enter their input directly
More informationCommunication With the Outside World
Communication With the Outside World Program Return Code Arguments From the Program Call Aborting Program Calling Other Programs Data Processing Course, I. Hrivnacova, IPN Orsay I. Hrivnacova @ Data Processing
More informationBIL 104E Introduction to Scientific and Engineering Computing. Lecture 14
BIL 104E Introduction to Scientific and Engineering Computing Lecture 14 Because each C program starts at its main() function, information is usually passed to the main() function via command-line arguments.
More informationRecitation 2/18/2012
15-213 Recitation 2/18/2012 Announcements Buflab due tomorrow Cachelab out tomorrow Any questions? Outline Cachelab preview Useful C functions for cachelab Cachelab Part 1: you have to create a cache simulator
More informationEL2310 Scientific Programming LAB2: C lab session. Patric Jensfelt, Andrzej Pronobis
EL2310 Scientific Programming LAB2: C lab session Patric Jensfelt, Andrzej Pronobis Chapter 1 Introduction 1.1 Reporting errors As any document, this document is likely to include errors and typos. Please
More informationC++ Lab 02 - Command Line Arguments and Strings
C++ Lab 02 - Command Line Arguments and Strings 2.680 Unmanned Marine Vehicle Autonomy, Sensing and Communications Spring 2015 Michael Benjamin, mikerb@mit.edu Department of Mechanical Engineering Computer
More informationG52CPP C++ Programming Lecture 3. Dr Jason Atkin
G52CPP C++ Programming Lecture 3 Dr Jason Atkin E-Mail: jaa@cs.nott.ac.uk 1 Revision so far C/C++ designed for speed, Java for catching errors Java hides a lot of the details (so can C++) Much of C, C++
More informationcs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).
cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion
More information518 Lecture Notes Week 3
518 Lecture Notes Week 3 (Sept. 15, 2014) 1/8 518 Lecture Notes Week 3 1 Topics Process management Process creation with fork() Overlaying an existing process with exec Notes on Lab 3 2 Process management
More informationCSE 333 Lecture 9 - intro to C++
CSE 333 Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia & Agenda Main topic: Intro to C++ But first: Some hints on HW2 Labs: The
More informationWhy C++ is much more fun than C (C++ FAQ)?
From C to C++ Why C++ is much more fun than C (C++ FAQ)? 1. Classes & methods - OO design 2. Generic programming - Templates allow for code reuse 3. Stricter type system (e.g. function args) 4. Some run-time
More informationCommon Misunderstandings from Exam 1 Material
Common Misunderstandings from Exam 1 Material Kyle Dewey Stack and Heap Allocation with Pointers char c = c ; char* p1 = malloc(sizeof(char)); char** p2 = &p1; Where is c allocated? Where is p1 itself
More informationToday s Learning Objectives
Today s Learning Objectives 15-123 Systems Skills in C and Unix We will Review ints and modular arithmetic Learn basic Data types and Formats How Conditionals and loops work How Arrays are defined, accessed,
More informationBasic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable
Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is
More informationExercise 1.1 Hello world
Exercise 1.1 Hello world The goal of this exercise is to verify that computer and compiler setup are functioning correctly. To verify that your setup runs fine, compile and run the hello world example
More informationCITS2002 Systems Programming. Creating a new process using fork() 1 next CITS2002 CITS2002 schedule
1 next CITS2002 CITS2002 schedule Creating a new process using fork() fork() is very unusual because it returns different values in the (existing) parent process, and the (new) child process: the value
More informationLecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8
Today... Java basics S. Bowers 1 of 8 Java main method (cont.) In Java, main looks like this: public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World!"); Q: How
More informationFall 2015 COMP Operating Systems. Lab #3
Fall 2015 COMP 3511 Operating Systems Lab #3 Outline n Operating System Debugging, Generation and System Boot n Review Questions n Process Control n UNIX fork() and Examples on fork() n exec family: execute
More informationtoday cs3157-fall2002-sklar-lect05 1
today homework #1 due on monday sep 23, 6am some miscellaneous topics: logical operators random numbers character handling functions FILE I/O strings arrays pointers cs3157-fall2002-sklar-lect05 1 logical
More informationProblem Set 1: Unix Commands 1
Problem Set 1: Unix Commands 1 WARNING: IF YOU DO NOT FIND THIS PROBLEM SET TRIVIAL, I WOULD NOT RECOMMEND YOU TAKE THIS OFFERING OF 300 AS YOU DO NOT POSSESS THE REQUISITE BACKGROUND TO PASS THE COURSE.
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 informationENERGY 211 / CME 211. Functions
ENERGY 211 / CME 211 Lecture 8 October 8, 2008 1 Functions So far, we have seen programs in which all code resides within a main function Complex programs consist of subprograms that perform particular
More informationLecture 3 Memory and Pointers
Lecture 3 Memory and Pointers Lets think about memory We can think of memory as a series of empty slots Each cell in the slot will hold 1 Byte To identify which cell something is in we need an identifier.
More informationCE221 Programming in C++ Part 1 Introduction
CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationIntroduction to Supercomputing
Introduction to Supercomputing TMA4280 Introduction to UNIX environment and tools 0.1 Getting started with the environment and the bash shell interpreter Desktop computers are usually operated from a graphical
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 informationPROGRAMMING IN C++ CVIČENÍ
PROGRAMMING IN C++ CVIČENÍ INFORMACE Michal Brabec http://www.ksi.mff.cuni.cz/ http://www.ksi.mff.cuni.cz/~brabec/ brabec@ksi.mff.cuni.cz gmichal.brabec@gmail.com REQUIREMENTS FOR COURSE CREDIT Basic requirements
More informationare all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable.
CMPS 12M Introduction to Data Structures Lab Lab Assignment 3 The purpose of this lab assignment is to introduce the C programming language, including standard input-output functions, command line arguments,
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 informationCreating a Shell or Command Interperter Program CSCI411 Lab
Creating a Shell or Command Interperter Program CSCI411 Lab Adapted from Linux Kernel Projects by Gary Nutt and Operating Systems by Tannenbaum Exercise Goal: You will learn how to write a LINUX shell
More informationShell Script Programming 2
Shell Script Programming 2 David Morgan Useful capabilities parameter processing validation usage checking user input custom functions filenames decomposition, tempnames, random names action hinged on
More informationC++ Lab 03 - C++ Functions
C++ Lab 03 - C++ Functions 2.680 Unmanned Marine Vehicle Autonomy, Sensing and Communications Spring 2018 Michael Benjamin, mikerb@mit.edu Department of Mechanical Engineering Computer Science and Artificial
More informationCpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014)
CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014) Goals Demonstrate proficiency in the use of the switch construct and in processing parameter data passed to a program via the command
More informationC, C++, Fortran: Basics
C, C++, Fortran: Basics Bruno Abreu Calfa Last Update: September 27, 2011 Table of Contents Outline Contents 1 Introduction and Requirements 1 2 Basic Programming Elements 2 3 Application: Numerical Linear
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 informationSystems Programming/ C and UNIX
Systems Programming/ C and UNIX Alice E. Fischer September 6, 2017 Alice E. Fischer Systems Programming Lecture 2... 1/28 September 6, 2017 1 / 28 Outline 1 Booting into Linux 2 The Command Shell 3 Defining
More informationLecture 05 POINTERS 1
Lecture 05 POINTERS 1 Pointers Powerful, but difficult to master Simulate call-by-reference Close relationship with arrays and strings Pointer Variable vs. Normal Variable Normal variables contain a specific
More informationLooping and Counting. Lecture 3 Hartmut Kaiser hkaiser/fall_2012/csc1254.html
Looping and Counting Lecture 3 Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2012/csc1254.html Abstract First we ll discuss types and type safety. Then we will modify the program
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 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 informationCS2141 Software Development using C/C++ C++ Basics
CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short
More informationComputer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview
Computer Science 322 Operating Systems Mount Holyoke College Spring 2010 Topic Notes: C and Unix Overview This course is about operating systems, but since most of our upcoming programming is in C on a
More informationRecitation: Cache Lab & C
15-213 Recitation: Cache Lab & C Jack Biggs 16 Feb 2015 Agenda Buffer Lab! C Exercises! C Conventions! C Debugging! Version Control! Compilation! Buffer Lab... Is due soon. So maybe do it soon Agenda Buffer
More informationPointers cause EVERYBODY problems at some time or another. char x[10] or char y[8][10] or char z[9][9][9] etc.
Compound Statements So far, we ve mentioned statements or expressions, often we want to perform several in an selection or repetition. In those cases we group statements with braces: i.e. statement; statement;
More informationCarnegie Mellon. Cache Lab. Recitation 7: Oct 11 th, 2016
1 Cache Lab Recitation 7: Oct 11 th, 2016 2 Outline Memory organization Caching Different types of locality Cache organization Cache lab Part (a) Building Cache Simulator Part (b) Efficient Matrix Transpose
More informationChapter 13. Functions and Parameter Passing (Part 2)
Christian Jacob Chapter 13 Functions and Parameter Passing (Part 2) 13.1 Passing Arguments to Functions 13.1.1 Passing Pointers 13.1.2 Passing Arrays 13.1.3 Passing Strings 13.2 Parameter Passing Mechanisms
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 9 Pointer Department of Computer Engineering 1/46 Outline Defining and using Pointers
More informationSE350: Operating Systems
SE350: Operating Systems Tutorial: The Programming Interface Main Points Creating and managing processes fork, exec, wait Example: implementing a shell Shell A shell is a job control system Allows programmer
More informationFile IO and command line input CSE 2451
File IO and command line input CSE 2451 File functions Open/Close files fopen() open a stream for a file fclose() closes a stream One character at a time: fgetc() similar to getchar() fputc() similar to
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 For more information please consult Advanced Programming in the UNIX Environment, 3rd Edition, W. Richard Stevens and
More informationCSC209H Lecture 3. Dan Zingaro. January 21, 2015
CSC209H Lecture 3 Dan Zingaro January 21, 2015 Streams (King 22.1) Stream: source of input or destination for output We access a stream through a file pointer (FILE *) Three streams are available without
More informationUnix-Linux 2. Unix is supposed to leave room in the process table for a superuser process that could be used to kill errant processes.
Unix-Linux 2 fork( ) system call is successful parent suspended child created fork( ) returns child pid to parent fork( ) returns zero value to child; zero is the pid of the swapper/scheduler process both
More informationModule Contact: Dr Anthony J. Bagnall, CMP Copyright of the University of East Anglia Version 2
UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2014/15 PROGRAMMING 2 CMP-5015Y Time allowed: 2 hours Answer four questions. All questions carry equal weight. Notes are
More informationLab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them.
Lab 8 Each lab will begin with a recap of last lab and a brief demonstration by the TAs for the core concepts examined in this lab. As such, this document will not serve to tell you everything the TAs
More informationEL2310 Scientific Programming
Lecture 11: Memory, Files and Bitoperations (yaseminb@kth.se) Overview Overview Lecture 11: Memory, Files and Bit operations Main function; reading and writing Bitwise Operations Lecture 11: Memory, Files
More informationLecture 2, September 4
Lecture 2, September 4 Intro to C/C++ Instructor: Prashant Shenoy, TA: Shashi Singh 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due
More informationCSE 333 Lecture smart pointers
CSE 333 Lecture 14 -- smart pointers Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington Administrivia New exercise out today, due Wednesday morning Exam Friday
More informationProgrammazione. Prof. Marco Bertini
Programmazione Prof. Marco Bertini marco.bertini@unifi.it http://www.micc.unifi.it/bertini/ Hello world : a review Some differences between C and C++ Let s review some differences between C and C++ looking
More information8. Characters, Strings and Files
REGZ9280: Global Education Short Course - Engineering 8. Characters, Strings and Files Reading: Moffat, Chapter 7, 11 REGZ9280 14s2 8. Characters and Arrays 1 ASCII The ASCII table gives a correspondence
More informationLooping and Counting. Lecture 3. Hartmut Kaiser hkaiser/fall_2011/csc1254.html
Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2011/csc1254.html 2 Abstract First we ll discuss types and type safety. Then we will modify the program we developed last time (Framing
More informationModel-Based Testing. (DIT848 / DAT261) Spring Lecture 3 White Box Testing - Coverage
Model-Based Testing (DIT848 / DAT261) Spring 2017 Lecture 3 White Box Testing - Coverage Gerardo Schneider Dept. of Computer Science and Engineering Chalmers University of Gothenburg Some slides based
More informationArray Initialization
Array Initialization Array declarations can specify initializations for the elements of the array: int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ; initializes primes[0] to 2, primes[1] to 3, primes[2]
More informationC++ Basics. Brian A. Malloy. References Data Expressions Control Structures Functions. Slide 1 of 24. Go Back. Full Screen. Quit.
C++ Basics January 19, 2012 Brian A. Malloy Slide 1 of 24 1. Many find Deitel quintessentially readable; most find Stroustrup inscrutable and overbearing: Slide 2 of 24 1.1. Meyers Texts Two excellent
More informationCSC 2400: Computer Systems. Arrays and Strings in C
CSC 2400: Computer Systems Arrays and Strings in C Lecture Overview Arrays! List of elements of the same type Strings! Array of characters ending in \0! Functions for manipulating strings 1 Arrays: C vs.
More informationCOMP s1 Lecture 1
COMP1511 18s1 Lecture 1 1 Numbers In, Numbers Out Andrew Bennett more printf variables scanf 2 Before we begin introduce yourself to the person sitting next to you why did
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 informationCE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings
CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings 19/10/2017 CE221 Part 2 1 Variables and References 1 In Java a variable of primitive type is associated with a memory location
More informationAgenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures
The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF
More informationMartin Brunner, Jonas Pfoh Sept. 6, Sept. 24, 2010
Martin Brunner, Jonas Pfoh martin.brunner@sit.fraunhofer.de;pfoh@sec.in.tum.de IT Security Lab Technische Universität München Munich, Germany Sept. 6, 2010 - Sept. 24, 2010 Outline 1 2 3 4 5 6 Welcome
More informationHomework 4. Any questions?
CSE333 SECTION 8 Homework 4 Any questions? STL Standard Template Library Has many pre-build container classes STL containers store by value, not by reference Should try to use this as much as possible
More informationCS3157: Advanced Programming. Outline
CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch
More informationC++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay
C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming
More informationCOMP26120: Pointers in C (2018/19) Lucas Cordeiro
COMP26120: Pointers in C (2018/19) Lucas Cordeiro lucas.cordeiro@manchester.ac.uk Organisation Lucas Cordeiro (Senior Lecturer, FM Group) lucas.cordeiro@manchester.ac.uk Office: 2.44 Office hours: 10-11
More informationWeek 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430
Week 2 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430 1 Why is the Shell Important? Shells provide us with a way to interact with the core system Executes programs on
More informationLab 1: First Steps in C++ - Eclipse
Lab 1: First Steps in C++ - Eclipse Step Zero: Select workspace 1. Upon launching eclipse, we are ask to chose a workspace: 2. We select a new workspace directory (e.g., C:\Courses ): 3. We accept the
More informationLaboratory 1 Semester 1 11/12
CS2106 National University of Singapore School of Computing Laboratory 1 Semester 1 11/12 MATRICULATION NUMBER: In this lab exercise, you will get familiarize with some basic UNIX commands, editing and
More informationGeneral Computer Science II Course: B International University Bremen Date: Dr. Jürgen Schönwälder Deadline:
General Computer Science II Course: 320102-B International University Bremen Date: 2004-04-28 Dr. Jürgen Schönwälder Deadline: 2004-05-14 Problem Sheet #7 This problem sheet focusses on C++ casting operators
More informationCSCI-1200 Data Structures Fall 2017 Lecture 2 STL Strings & Vectors
Announcements CSCI-1200 Data Structures Fall 2017 Lecture 2 STL Strings & Vectors HW 1 is available on-line through the website (on the Calendar ). Be sure to read through this information as you start
More informationAgenda. Components of a Computer. Computer Memory Type Name Addr Value. Pointer Type. Pointers. CS 61C: Great Ideas in Computer Architecture
CS 61C: Great Ideas in Computer Architecture Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c And in Conclusion, 2 Processor Control Datapath Components of a Computer PC Registers Arithmetic
More informationLecture 10. Command line arguments Character handling library void* String manipulation (copying, searching, etc.)
Lecture 10 Class string Namespaces Preprocessor directives Macros Conditional compilation Command line arguments Character handling library void* TNCG18(C++): Lec 10 1 Class string Template class
More informationBiostatistics 615/815 - Lecture 2 Introduction to C++ Programming
Biostatistics 615/815 - Lecture 2 Introduction to C++ Programming Hyun Min Kang September 8th, 2011 Hyun Min Kang Biostatistics 615/815 - Lecture 2 September 8th, 2011 1 / 47 BIOSTAT615/815 - Objectives
More informationCS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Krste Asanović & Randy Katz
CS 61C: Great Ideas in Computer Architecture Lecture 3: Pointers Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Agenda Pointers in C Arrays in C This is not on the test Pointer arithmetic
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 informationUNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Summer 2016 Programming Assignment 1 Introduction The purpose of this
UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Summer 2016 Programming Assignment 1 Introduction The purpose of this programming assignment is to give you some experience
More informationAPT Session 4: C. Software Development Team Laurence Tratt. 1 / 14
APT Session 4: C Laurence Tratt Software Development Team 2017-11-10 1 / 14 http://soft-dev.org/ What to expect from this session 1 C. 2 / 14 http://soft-dev.org/ Prerequisites 1 Install either GCC or
More informationjust a ((somewhat) safer) dialect.
Intro_to_C Page 1 Intro to C Tuesday, September 07, 2004 5:30 PM C was developed specifically for writing operating systems Low level of abstraction. "Just above machine language." Direct access to the
More informationCSC 2400: Computer Systems. Arrays and Strings in C
CSC 2400: Computer Systems Arrays and Strings in C Lecture Overview Arrays! List of elements of the same type Strings! Array of characters ending in \0! Functions for manipulating strings 1 Arrays in C
More informationAn overview of Java, Data types and variables
An overview of Java, Data types and variables Lecture 2 from (UNIT IV) Prepared by Mrs. K.M. Sanghavi 1 2 Hello World // HelloWorld.java: Hello World program import java.lang.*; class HelloWorld { public
More informationCSC 1600 Unix Processes. Goals of This Lecture
CSC 1600 Unix Processes q Processes Goals of This Lecture q Process vs. program q Context switching q Creating a new process q fork: process creates a new child process q wait: parent waits for child process
More information211: Computer Architecture Summer 2016
211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Data Representation I/O: - (example) cprintf.c Memory: - memory address - stack / heap / constant space - basic data layout Pointer:
More informationOverview (1A) Young Won Lim 9/14/17
Overview (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationC++ Programming for Non-C Programmers. Supplement
C++ Programming for Non-C Programmers Supplement ii C++ Programming for Non-C Programmers C++ Programming for Non-C Programmers Published by itcourseware, 10333 E. Dry Creek Rd., Suite 150, Englewood,
More informationExceptions. CS162: Introduction to Computer Science II. Exceptions. Exceptions. Exceptions. Exceptions. Exceptions
CS162: Introduction to Computer Science II A typical way to handle error conditions is through the return value. For example, suppose we create a loadfile() function that returns true if it loaded the
More information