A<int,60> array[100]; 100*60*sizeof(int)
|
|
- Sherman Parker
- 6 years ago
- Views:
Transcription
1 \ Y 1 Q Y Y 1 Template! "# & ')4,65')(754+8$')901:$;1$,<9=' $%!& ')( *+,)-0/ 132+'% Template file Ah: <class T1, class T2 T1 _d; T2 _c; ; A<double, int a; 1+@-,<P=$ & ')4D,65')(7G H/$,I& ')9JLM&-&,)% =$;N<2 ')* file Ah: <class T, int size T _array[size]; $ %?& ')(@*+,)-AB/ 1C2D+E'% F A<double,70 a1; A<double,100 a2; &ER5J, WRX $%7S=LL+8$R')90+@1C( G@')'<FT,)/8$R'<FU%EFV&ER5 & ')'+R5M% 5'I$ *1 Y double 18, 1:'1:' $% [ XRX $%ZSJLJ+8$')90+ 13( G@')'<FT,)/8$R'<FU%EF 70*sizeof(double) a1 sizeof double 1'1:' $% 100*sizeof(double) a2 sizeof 1/:FT181:B,)%1C2/CFU,<2 9J*I$%+$;&/ A<int,60 array[100]; $ %Z2D,)/E')=G@$ 2+EB,)-& ')( G ')'<FU,)/8$%7S=LL+82 =')^0' & ')2F S=J+ 13$]M,<^0G,<' 100*60*sizeof(int) 2@'+E*)')PH1I^0GD1 FV& '<^=FU+7,<*)')'18&/ & ')J(+L5M_L')4D,)1$;N<2@')*:/$`1:$/82D,)/E')JG $ A,<$RP0,)-1:'1:':1+ 1:*,<=a@/@1CP0,<GD1C2@0,)%EFVN<')')^0$;1:'1C0%E5L/8'/ default S=J+8$% ctor <typename T, T val class A { void foo() { std::cout << val << std::endl; ; A<int,7 a; 1+ -,<PJ$ & P0,<G7( *+@,)-A0/84D,65')(+82D,<'1:$b$9='TS=L;(@*+,)-AB/ 1
2 ) ; E ; ; ; G E A<char,'h' b; // A<char,78 c; // compilation error afoo(); bfoo(); 7 h 4 1 ' ) =!0 <!$# 8 8* &:,8 1 default file Ah: <class T = double, int size = 50 T _array[size]; ; A< d; // similar to: A<double,50 A<int h; // similar to: A<int,50 A<float,70 z; % 0/*1 )2 & 354!6'! * &:,8 1 3 default "!$# &%('*),+default 3 %('*=),+" 4 + A 4! C4!</ '( &4 B 8@'D) 1 1 B 3 file Ah: Type _data; A(Type data) : _data(data) { bool isbegger(type data); ; specialization - +0) / 4 -?8@) ) 1 A(1B 4 ' # <class Type bool A<Type::isBegger(Type data) { return data _data; #include Ah A<char* a( hi ); std::cout << aisbigger( bye ); 3LJ!$# 3DJ!# %%() ) 3@) -H-I),8 3D+0) / % % 0! %-F%!"/* %(' E _data 86) M)!"A '*%N86), data A 8@'D4@%-F: )!<" M -8@) isbigger() '*) / '*%P 3L86)2-Q),8 4@%%R 4 1 8@3@' 73S4 "!$# %! 7T@' hi! 8@) %R ),+0=(: %('D%*M B/ ),+$-?8@)Q%R %P8@)2-Q),8 %P8 %() ) 3*8 % 0/*1 )2 "% E : -8 U! =) /* T / &% ) ) 3@%V% %R863S) 1 0! 8!<A %R8 %P+0) / %P8U- isbigger() 8 -F) 1 73S% 1 ) ) %(3 bye!< -?T 2
3 & 4 H : H : H H! "! #$ #%'&()!* + ",- % file Ah (/0 123/ ): bool A<char*::isBigger(char *data) { return strcmp(data, _data) 0; 4 56&7 %8 99& A<int ai(5); A<char* as( hi ); aiisbigger(7); // generic isbigger() asisbigger( bye ); // specific isbigger() specialization #include <stringh char* %;<! = % #%+%; =!8 I #+J +%; CB8# " &(,- %$B!%DBEFG$ 8 % 9@ $ -#$CB A $ & # 9 %;<I#@ FG, ;F ; specialization matching N< ÖLBA%8 " A<String specialization FG ";"L +7 M ;$L B# L% %R 9 ;S -! # HQP global function E,*E 9"E'&7 EF+ %; ;? ;9 A &-@ operator << "99 L - %N; SLB88&( ; %6 9,& +%; <class Type void foo(type d) { H H foo(5); // the function foo(int) will be expand and called foo(55); // the function foo(double) will be expand and called foo(21); // the function foo(double) will be called but will not be expand again int i = 5; foo(&i); // the function foo(int*) will be expand and called (Type = int* ) 88@A E!VB &+7$ #,FGLF # ;F; <class Type void foo(type* p) { int d; foo(&d); // foo(int *) will be expand and called (Type = int) ;F ; L $ CB! $L"99 9@('+%; #* " Type 9F, U&-@ - $ 8@ M!VB &+7$ +%; #* NCB8#<& & '' #%& B &-+7 W!! XB &-+7 +%; 9 % &Y999 ;F; 3
4 A #include "LinkedListh" <typename T void foo1(linkedlist<t* list) { <typename T void foo2(linkedlist<linkedlist<t* list) { LinkedList<int* list; LinkedList<LinkedList<int* ll; foo1(list); // T = int foo1(ll); // T = LinkedList<int foo2(ll);; // T = int! " # $! '!*" &, - / & 0 & ) 12 3#! % '&(!)*") & % ) 2 2")55 &4! "* & &4 <class T1, class T2 void foo(t1 t) { T2 data; foo(5); // T2 =?? "! foo() <class T1, class T2 void foo(t2 t2, T1 t1) { T2 data; #! &(!)*") & 1 T2 foo()! "/, & / 0 9 &4:!*<, & - ; / " & T2 ") & & 2-!! %?,, &( #!) & & : = )9 & - compile-time polymorphism Templates 9 = =7 polymorphism -5< B "! $,=C D- / D & :! )!3?, & %# 2 0 1#! /!C# 2 : /" # / 7 D 0 -# 2# & 78/, & & : C- 9) /,=C; - polymorphism s, : E7? =, : E7 D0 #include <iostream <typename T void foo(t t) { tprint(); // compile time polymorphism polymorphism 4
5 ; void print() { std::cout << "I'm a happy instance of A" << std::endl; class B { void print() { std::cout << "I'm a sad instance of B" << std::endl; ; A a; B b; foo(a); foo(b); #include <iostream run-time-polymorphism s class DataStructure { virtual ostream& tostream(ostream& os) const = 0; ; ostream& operator << (ostream& os, const DataStructure& ds) { return dstostream(os); <typename T class List :public DataStructure { virtual ostream& tostream(ostream& os) const { return os<<"i'm a list of " << T::getType() << std::endl; ; <typename T class Tree : public DataStructure { virtual ostream& tostream(ostream& os) const { return os<<"i'm a tree of " << T::getType() << std::endl; ; static char* gettype() {return "A"; 5
6 N & 3 ; class B { static char* gettype() {return "B"; ; Tree<A ta; Tree<B tb; List<A la; List<B lb; std::cout << ta << tb << la << lb; return 0; '( ) *" +!"#"$% #include <iostream #include "LinkedListh" A BC19*DE2/ 13E249 compile-time run-time, DataStructure -/ #89;:2/<*=?624@ # G #!%)HI6J *"%L%F %I ' ) M virtual void print(ostream& os) const =0; ; ostream& operator << (ostream& os, const A* a) { a-print(os); return os; class B : public A { virtual void print(ostream& os) const { os << "B print"; ; class C : public A { virtual void print(ostream& os) const { os << "C print"; ; B b1,b2; C c1,c2; LinkedList<A* list; listinsert(&b1); listinsert(&c1); listinsert(&c2); listinsert(&b2); std::cout << list << std::endl; %F ' 6
7 ( ( - B print - C print - C print - B print ) *! * + *,- )! "! #%$ & ' * $ /10* :5;"<"//4=*76)=?<A@5B/C0D243"E"/27F 25A24=!@G)H%/10*243AE"F /C0I731)65"@37J A L " M" N! L + ' * '# #include <iostream #include <stdlibh <typename T class Less { bool operator() (const T& t1, const T& t2) const { return t1 < t2; ; <typename T class More { bool operator() (const T& t1, const T& t2) const { return t1 t2; ; class DigitLess { int digitsum(const int& t) const { return t-9*(t/10); // good only for two digits number bool operator() (const int& t1, const int& t2) const { return digitsum(t1) < digitsum(t2); ; <typename T void swap(t& t1, T& t2) { T tmp(t1); t1 = t2; t2 = tmp; <typename DS, typename CMP void sort(ds& ds, const CMP& cmp) { for(int i=0; i<dssize(); i++) for(int j=i+1; j<dssize(); j++) if(cmp(ds[j],ds[i])) swap(ds[j],ds[i]); 7
8 <typename T, int SIZE class Array { T _arr[size]; const T& operator[](int i) const { return _arr[i]; T& operator[](int i) { return _arr[i]; int size() {return SIZE; ; <typename T, int SIZE ostream& operator << (ostream& os, const Array<T,SIZE& arr) { for(int i=0; i<size; i++) os << ' ' << arr[i]; return os << ' '; Array<int,20 ar1; Array<double,20 ar2; for(int i=0; i<20; i++) ar2[i] = ar1[i] = i; sort(ar1,less<int()); sort(ar2,more<double()); std::cout << ar1 << " " << std::endl << ar2 << std::endl; sort(ar1,digitless()); std::cout << ar1 << std::endl;
Before we dive in. Preprocessing Compilation Linkage
Templates Before we dive in Preprocessing Compilation Linkage 2 Motivation A useful routine to have is void swap( int& a, int &b ) int tmp = a; a = b; b = tmp; 3 Example What happens if we want to swap
More informationCOSC 320 Exam 2 Key Spring Part 1: Hash Functions
COSC 320 Exam 2 Key Spring 2011 Part 1: Hash s 1. (5 Points) Create the templated function object lessthan, you may assume that the templated data type T has overloaded the < operator. template
More informationProgramming in C++: Assignment Week 8
Programming in C++: Assignment Week 8 Total Marks : 20 Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology Kharagpur 721302 partha.p.das@gmail.com April 12,
More informationECE Fall 2017, Third Exam
ECE 30862 Fall 2017, Third Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. LEAVE IT ON THE DESK. THE LAST PAGE IS THE ANSWER SHEET. TEAR IT OFF AND PUT ALL ANSWERS THERE. TURN IN BOTH PARTS OF THE
More informationTDDD38 - Advanced programming in C++
TDDD38 - Advanced programming in C++ Templates III Christoffer Holm Department of Computer and information science 1 Dependent Names 2 More on Templates 3 SFINAE 1 Dependent Names 2 More on Templates 3
More informationBell Bjarne Stroustrup C C with classes Stroustrup C C with classes
C++ C++ BellBjarne Stroustrup C C with classes C with classes Stroustrup C C with classes C C++C++ ++CC CC+1 CC++ CC++ C++CCC++ C++ CC++ structc C++ C++ templateso.o C++compile-time-polymorphism const
More informationECE Fall 2018, Test 3
1 ECE 30862 Fall 2018, Test 3 DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. LEAVE IT ON THE DESK. THE LAST PAGE IS THE ANSWER SHEET. TEAR IT OFF AND PUT ALL ANSWERS THERE. TURN IN BOTH PARTS OF THE
More informationECE 462 Fall 2011, Second Exam
ECE 462 Fall 2011, Second Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. You have until 9:20 to take this exam. Your exam should have 10 pages total (including this cover sheet). Please let Prof.
More informationProgramming in C++: Assignment Week 1
Programming in C++: Assignment Week 1 Total Marks : 20 Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology Kharagpur 721302 partha.p.das@gmail.com February 24,
More informationstruct Buffer { Buffer(int s) { buf = new char[s]; } ~Buffer() { delete [] buf; } char *buf; };
struct Buffer { Buffer(int s) { buf = new char[s]; ~Buffer() { delete [] buf; char *buf; ; struct FBuffer : public Buffer { FBuffer(int s) : Buffer(s) { f = fopen("file", "w"); ~FBuffer() { fclose(f);
More informationC++ Pub Quiz. A 90 minute quiz session ACCU April by Olve Maudal, with Lars Gullik Bjønnes. Sponsored by:
C++ Pub Quiz by Olve Maudal, with Lars Gullik Bjønnes + + Sponsored by: A 90 minute quiz session ACCU April 2013 Here is my development environment: (Mac OS 10.8.2, x86_64) bash-3.2$ myc++ -v Using built-in
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 informationLambda functions. Zoltán Porkoláb: C++11/14 1
Lambda functions Terminology How it is compiled Capture by value and reference Mutable lambdas Use of this Init capture and generalized lambdas in C++14 Constexpr lambda and capture *this and C++17 Zoltán
More informationCOEN244: Class & function templates
COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library
More informationStructuur van Computerprogramma s 2
Structuur van Computerprogramma s 2 dr. Dirk Deridder Dirk.Deridder@vub.ac.be http://soft.vub.ac.be/ Vrije Universiteit Brussel - Faculty of Science and Bio-Engineering Sciences - Computer Science Department
More informationOutline. Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples.
Outline Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples. 1 Arrays I Array One type of data structures. Consecutive group of memory locations
More informationC++14 Reflections Without Macros, Markup nor External Tooling
C++14 Reflections Without Macros, Markup nor External Tooling Metaprogramming Tricks for POD Types Antony Polukhin Boost libraries maintainer (DLL, LexicalCast, Any, TypeIndex, Conversion) + Boost.CircularBuffer,
More informationECE Fall 2014, Final Exam
ECE 30862 Fall 2014, Final Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. LEAVE IT ON THE DESK. THE LAST TWO PAGES ARE THE ANSWER SHEETS. TEAR THEM OFF AND PUT ALL ANSWERS ON THEM. TURN IN BOTH
More informationCSE 333 Midterm Exam Cinco de Mayo, 2017 (May 5) Name UW ID#
Name UW ID# There are 6 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,
More informationECE Fall 20l2, Second Exam
ECE 30862 Fall 20l2, Second Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. LEAVE IT ON THE DESK. You have until 12:20 to take this exam. Your exam should have 16 pages total (including this cover
More informationMore Functions. Pass by Value. Example: Exchange two numbers. Storage Classes. Passing Parameters by Reference. Pass by value and by reference
Pass by Value More Functions Different location in memory Changes to the parameters inside the function body have no effect outside of the function. 2 Passing Parameters by Reference Example: Exchange
More informationCS31 Discussion. Jie(Jay) Wang Week8 Nov.18
CS31 Discussion Jie(Jay) Wang Week8 Nov.18 Outline Pointer Struct Memory Management When the program gets executed, it gets some amount of memory allocated for use. memory Program 1 Program 2 Memory Management
More informationCOMP 2355 Introduction to Systems Programming
COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Today Templates Operator Overloading 2 Templates Syntactically similar to Java generics
More informationCS 225. September 24 Iterators. Data Structures. Wade Fagen-Ulmschneider
CS 225 Data Structures September 24 Iterators Wade Fagen-Ulmschneider CS 225 So Far List ADT Linked Memory Implementation ( Linked List ) O(1) insert/remove at front/back O(1) insert/remove after a given
More informationArrays and Pointers in C. Alan L. Cox
Arrays and Pointers in C Alan L. Cox alc@rice.edu Objectives Be able to use arrays, pointers, and strings in C programs Be able to explain the representation of these data types at the machine level, including
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 informationUNDEFINED BEHAVIOR IS AWESOME
UNDEFINED BEHAVIOR IS AWESOME Piotr Padlewski piotr.padlewski@gmail.com, @PiotrPadlewski ABOUT MYSELF Currently working in IIIT developing C++ tooling like clang-tidy and studying on University of Warsaw.
More informationCS 7B - Spring Final Exam
CS 7B - Spring 2018 - Final Exam Write your responses to following questions on this paper, or attach extra, as needed. sentences where appropriate and write out code using proper style and syntax. 1.
More informationC - Func(on, Pointer, Array. Zhaoguo Wang
C - Func(on, Pointer, Array Zhaoguo Wang A gigantic main loop https://github.com/qemu/qemu/blob/master/vl.c Function Readability Reusability Function int add(int a, int b) { int r = a + b; return r; name
More informationLecture 2 Polymorphism, Traits, Policies, and Inheritance
Lecture 2 Polymorphism, Traits, Policies, and Inheritance Kenny Erleben Department of Computer Science University of Copenhagen c K. Erleben, May 4, 2006 p. 1/36 Polymorphism 1 Traditional, define abstract
More information1. The term STL stands for?
1. The term STL stands for? a) Simple Template Library b) Static Template Library c) Single Type Based Library d) Standard Template Library Answer : d 2. Which of the following statements regarding the
More informationCAAM 420 Fall 2012 Lecture 29. Duncan Eddy
CAAM 420 Fall 2012 Lecture 29 Duncan Eddy November 7, 2012 Table of Contents 1 Templating in C++ 3 1.1 Motivation.............................................. 3 1.2 Templating Functions........................................
More informationArrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors
Arrays Returning arrays Pointers Dynamic arrays Smart pointers Vectors To declare an array specify the type, its name, and its size in []s int arr1[10]; //or int arr2[] = {1,2,3,4,5,6,7,8}; arr2 has 8
More informationAdvanced C++ Topics. Alexander Warg, 2017
www.kernkonzept.com Advanced C++ Topics Alexander Warg, 2017 M I C R O K E R N E L M A D E I N G E R M A N Y Overview WHAT IS BEHIND C++ Language Magics Object Life Time Object Memory Layout INTRODUCTION
More informationOutline. User-dened types Categories. Constructors. Constructors. 4. Classes. Concrete classes. Default constructor. Default constructor
Outline EDAF50 C++ Programming 4. Classes Sven Gestegård Robertz Computer Science, LTH 2018 1 Classes the pointer this const for objects and members Copying objects friend inline 4. Classes 2/1 User-dened
More informationCS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Bernhard Boser & Randy Katz
CS 61C: Great Ideas in Computer Architecture Lecture 3: Pointers Bernhard Boser & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Agenda Pointers in C Arrays in C This is not on the test Pointer arithmetic
More informationExercise 7 References, Arrays, Vectors
Exercise 7 References, Arrays, Vectors Informatik I für Mathematiker und Physiker (HS 2015) Yeara Kozlov Slides courtesy of Kaan Yücer & Endri Dibra B. Gaertner, ETH Zürich, 2015 Agenda HW #5 Feedback
More informationProgramming in C++: Assignment Week 8
Programming in C++: Assignment Week 8 Total Marks : 20 September 9, 2017 Question 1 Consider the following code segment. Mark 2 void myfunction(int test) { try { if (test) throw test; else throw "Value
More informationWhat will happen if we try to compile, link and run this program? Do you have any comments to the code?
1 # include < iostream > 2 3 int main () 4 { 5 std :: cout
More informationC Arrays, Strings, More Pointers Instructor: Steven Ho
C Arrays, Strings, More Pointers Instructor: Steven Ho Review of Last Lecture C Basics Variables, Functions, Flow Control, Types, and Structs Only 0 and NULL evaluate to FALSE Pointers hold addresses Address
More informationeingebetteter Systeme
Praktikum: Entwicklung interaktiver eingebetteter Systeme C++-Tutorial (falk@cs.fau.de) 1 Agenda Classes Pointers and References Functions and Methods Function and Operator Overloading Template Classes
More information1 Basic considerations
C++ syntax-only reference card v.0.28 P. Areias (UEVORA) October 12, 2013 1 Basic considerations 1.1 Notation indicates that the programmer must provide an appropriate replacement. example expr can be
More informationYour first C and C++ programs
Your first C and C++ programs 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 informationE.C. 2 E.C. 1 E.C.
Computer Chocolate Code-off: Rules: 1. Create one answer sheet with all group member names on it! (to be given to another group for grading No running code (you may use class notes) 2. You may ask yes/no
More information1d: tests knowing about bitwise fields and union/struct differences.
Question 1 1a: char ptr[] = Hello World ; char a = ptr[1], b = *(ptr+6); Creates an array of 12 elements, 11 visible letters and a character value 0 at the end. i true ii true iii false iv false v true
More informationComp151. Generic Programming: Container Classes
Comp151 Generic Programming: Container Classes Container Classes Container classes are a typical use for class templates, since we need container classes for objects of many different types, and the types
More informationThe paramaterless ctor (aka default ctor)
Initialization List The paramaterless ctor (aka default ctor) 2 int main() B b; class A public: A() std::cout
More informationMove semantics. Zoltán Porkoláb: C++11/14 1
Move semantics Pointers and arrays References Value vs move semantics Right value references Move semantics in C++11 Perfect forwarding Traps and pitfalls Zoltán Porkoláb: C++11/14 1 Arrays An array is
More informationLesson 11: Generic Programming. EE3490E: Programming S1 2018/2019 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology
Lesson 11: Generic Programming 1 Function templates 2 General Occasionally, we like to write once but have many functions/methods with arguments of different types, instead of writing multiple overloaded
More informationECE 461 Fall 2011, Final Exam
ECE 461 Fall 2011, Final Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. LEAVE IT ON THE DESK. You have until 9:00PM to take this exam. Your exam should have 17 pages total (including this cover
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 informationCS 61c: Great Ideas in Computer Architecture
Arrays, Strings, and Some More Pointers June 24, 2014 Review of Last Lecture C Basics Variables, functioss, control flow, types, structs Only 0 and NULL evaluate to false Pointers hold addresses Address
More informationCOMP6771 Advanced C++ Programming
1........ COMP6771 Advanced C++ Programming Week 4 Part Three: Function Objects and 2016 www.cse.unsw.edu.au/ cs6771 2........ Converting Class Types to bool Convenient to use a class object as bool to
More informationECE Fall 2018, Test 2
1 ECE 30862 Fall 2018, Test 2 DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. LEAVE IT ON THE DESK. THE LAST PAGE IS THE ANSWER SHEET. TEAR IT OFF AND PUT ALL ANSWERS THERE. TURN IN BOTH PARTS OF THE
More informationPointers and Arrays CS 201. This slide set covers pointers and arrays in C++. You should read Chapter 8 from your Deitel & Deitel book.
Pointers and Arrays CS 201 This slide set covers pointers and arrays in C++. You should read Chapter 8 from your Deitel & Deitel book. Pointers Powerful but difficult to master Used to simulate pass-by-reference
More informationTopics. bool and string types input/output library functions comments memory allocation templates classes
C++ Primer C++ is a major extension of c. It is similar to Java. The lectures in this course use pseudo-code (not C++). The textbook contains C++. The labs involve C++ programming. This lecture covers
More informationUniversity of Illinois at Urbana-Champaign Department of Computer Science. First Examination
University of Illinois at Urbana-Champaign Department of Computer Science First Examination CS 225 Data Structures and Software Principles Summer 2005 3:00pm 4:15pm Tuesday, July 5 Name: NetID: Lab Section
More informationObject-Oriented Principles and Practice / C++
Object-Oriented Principles and Practice / C++ Alice E. Fischer June 3, 2013 OOPP / C++ Lecture 9... 1/40 Const Qualifiers Operator Extensions Polymorphism Abstract Classes Linear Data Structure Demo Ordered
More informationDesign Patterns in C++
Design Patterns in C++ Template metaprogramming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa April 6, 2011 G. Lipari (Scuola Superiore Sant Anna) Template metaprogramming
More informationDesign Patterns in C++
Design Patterns in C++ Template metaprogramming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa April 6, 2011 G. Lipari (Scuola Superiore Sant Anna) Template metaprogramming
More informationCS 110 Computer Architecture. Lecture 4: Introduction to C, Part III. Instructor: Sören Schwertfeger.
CS 110 Computer Architecture Lecture 4: Introduction to C, Part III Instructor: Sören Schwertfeger http://shtech.org/courses/ca/ School of Information Science and Technology SIST ShanghaiTech University
More informationChapter 4: Arrays, Pointers and Strings
Chapter 4: Arrays, Pointers and Strings C Programming Language Šimon Řeřucha v3.2 March 1, 2016 A C program is like a fast dance on a newly waxed dance floor by people carrying razors. Waldi Ravens. Advanced
More informationDebug C++ Without Running. Anastasia Kazakova
Debug C++ Without Running Anastasia Kazakova JetBrains @anastasiak2512 Agenda 1. Tricky C++ language. Show samples! 2. Seems to help but it doesn t. Why? Running / Debugging Static / dynamic code analysis
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 informationPolymorphism. Polymorphism. Person. class Person { void outputdetails(std::ostream& os=std::cout) const;
Polymorphism! " "#$&%#(')"+,"( -/)02#3#"4%!567 783 4)"+,":;FGE/#3@H#/C 783I+&7 J$C A" Polymorphism K LM2LNOP,NGO M?O!QRTSU&U&O 67V7F (!DFG+&7/ 7G!E=WX+FDXFGE
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 information2. Which of the following will print the value 2 for the above code?
Computers are good at following instructions, but not at reading your mind. - Donald Knuth IMPORTANT QUESTIONS ON C LANGUAGE 1. What is the output of this program? char *ptr; char string[] = "How are you?";
More informationOverloaded Operators, Functions, and Students
, Functions, and Students Division of Mathematics and Computer Science Maryville College Outline Overloading Symbols 1 Overloading Symbols 2 3 Symbol Overloading Overloading Symbols A symbol is overloaded
More informationTemplates. Rupesh Nasre. OOAIA January 2018
Templates Rupesh Nasre. OOAIA January 2018 Queue Interface Queue(); ~Queue(); void void insert(int x); x); int int remove(); int int a[100]; int int head, head, tail; tail; ; ; Queue Implementation Queue()
More informationLow-Level Programming in C
Low-Level Programming in C Menu C Programming Language Pointers in C Pointer Arithmetic Type checking in C 2 No support for: C Language Array bounds checking Null dereferences checking Data abstraction,
More information09:30 12:00. CRingBuf 類 : a) CRingBuf(int size): b) ~CRingBuf(): c) bool get(int &data): read pointer 數,
立 C++ 1 99/06/22 09:30 12:00 什, 數 1. 不 參 2. 不 ( ) 3. 不 不 不 料 ( 不 不見, ), 4. 離 不 留 5. 論 律 理 6. CRingBuf 類 : 串流 路 料 理, ring buffer 來 料, ring buffer, 來 料, 念 write pointer 料, write pointer, read pointer 讀 料,
More informationSeptember 19,
September 19, 2013 1 Problems with previous examples Changes to the implementation will require recompilation & relinking of clients Extensions will require access to the source code Solutions Combine
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 informationCOMP6771 Advanced C++ Programming
1. COMP6771 Advanced C++ Programming Week 7 Part One: Member Templates and 2016 www.cse.unsw.edu.au/ cs6771 2. Member Templates Consider this STL code: 1 #include 2 #include 3 #include
More informationC ++ Workshop Day 1 out of 5
C ++ Workshop Day 1 out of 5 Object Thierry Géraud, Roland Levillain, Akim Demaille {theo,roland,akim}@lrde.epita.fr EPITA École Pour l Informatique et les Techniques Avancées LRDE Laboratoire de Recherche
More informationCar. 9-2.cpp. Car cars[3]; p11-1.cpp. int main( ) { int i;
C++ 1. again 2. 3. Intelligent Electronic Systems Group 2 using namespace (Q)std::cout"std::" (A)stdcout #include using namespace std; //std C++ :: using namespace std; cout
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 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 informationCS
CS 1666 www.cs.pitt.edu/~nlf4/cs1666/ Programming in C++ First, some praise for C++ "It certainly has its good points. But by and large I think it s a bad language. It does a lot of things half well and
More informationSol. Sol. a. void remove_items_less_than(int arr[], int size, int value) #include <iostream> #include <ctime> using namespace std;
r6.14 For the operations on partially filled arrays below, provide the header of a func tion. d. Remove all elements that are less than a given value. Sol a. void remove_items_less_than(int arr[], int
More informationC++ Modern and Lucid C++ for Professional Programmers
Informatik C++ Modern and Lucid C++ for Professional Programmers part 9 Prof. Peter Sommerlad Institutsleiter IFS Institute for Software Rapperswil, HS 2015 Functors and Parameterizing STL Functors, Lambdas,
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 informationfor (int i = 1; i <= 3; i++) { do { cout << "Enter a positive integer: "; cin >> n;
// Workshop 1 #include using namespace std; int main () int n, k; int sumdigits; for (int i = 1; i n; cin.clear (); cin.ignore (100,
More informationPrinciples of Programming Languages, Exercise 1 (8+8 pts) Exercise 2 (8 pts) Exercise 3 (8 pts)
Principles of Programming Languages, 2012.07.23 Notes: - Total available time: 2h. - You may use any written material you need. - You cannot use computers, phones or laptops during the exam. Exercise 1
More informationTemplates. Zoltán Porkoláb: C++11/14 1
Templates From macros to templates Parameter deduction, instantiation,specialization Class templates, partial specialization Explicit instantiation Dependent types Scope resolution, lookup Mixins CRTP
More informationCS 61C: Great Ideas in Computer Architecture C Pointers. Instructors: Vladimir Stojanovic & Nicholas Weaver
CS 61C: Great Ideas in Computer Architecture C Pointers Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/sp16 1 Agenda Pointers Arrays in C 2 Address vs. Value Consider
More informationSFU CMPT Topic: Class Templates
SFU CMPT-212 2008-1 1 Topic: Class Templates SFU CMPT-212 2008-1 Topic: Class Templates Ján Maňuch E-mail: jmanuch@sfu.ca Monday 3 rd March, 2008 SFU CMPT-212 2008-1 2 Topic: Class Templates Class templates
More informationPointers and Strings Prentice Hall, Inc. All rights reserved.
Pointers and Strings 1 sizeof operator Pointer Expressions and Pointer Arithmetic Relationship Between Pointers and Arrays Arrays of Pointers Case Study: Card Shuffling and Dealing Simulation sizeof operator
More informationComputer Systems C S Cynthia Lee
Computer Systems C S 1 0 7 Cynthia Lee 2 Today s Topics FUNCTION POINTERS AND CALLBACKS (This is a continuation of our theme of making generic functions in C) New tool: Function pointer mechanism for callbacks
More informationDAY 3. CS3600, Northeastern University. Alan Mislove
C BOOTCAMP DAY 3 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh and Pascal Meunier s course at Purdue Memory management 2 Memory management Two
More informationSTRICT_VARIANT. A simpler variant in C++ Chris Beck
STRICT_VARIANT A simpler variant in C++ Chris Beck https://github.com/cbeck88/strict_variant What is a variant? A variant is a heterogenous container. std::vector many objects of one type std::variant
More informationObject Oriented Programming in C++
Object Oriented Programming in C++ Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague Lecture 11 B3B36PRG C Programming Language Jan Faigl,
More informationCSE 333. Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington
CSE 333 Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia New exercise posted yesterday afternoon, due Monday morning - Read a directory
More informationBiostatistics 615/815 Lecture 13: Numerical Optimization
Biostatistics 615/815 Lecture 13: Numerical Optimization Hyun Min Kang October 27th, 2011 Hyun Min Kang Biostatistics 615/815 - Lecture 13 October 27th, 2011 1 / 35 The Problem Hyun Min Kang Biostatistics
More informationArizona s First University. ECE 373. Operation Overloading. The Revolution Operation Will Be Televised (and, these slides will be online later today)
Arizona s First University. ECE 373 Operation Overloading The Revolution Operation Will Be Televised (and, these slides will be online later today) Previously, on ECE373 Families of operators can be overloaded
More informationArrays and Memory Management
Arrays and Memory Management 1 Pointing to Different Size Objects Modern machines are byte-addressable Hardware s memory composed of 8-bit storage cells, each has a unique address A C pointer is just abstracted
More informationAbstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles
Abstract Data Types (ADTs) CS 247: Software Engineering Principles ADT Design An abstract data type (ADT) is a user-defined type that bundles together: the range of values that variables of that type can
More informationValue categories. PRvalues. Lvalues
Value categories v5 Every C++14 expression belongs to exactly one of the following classifications, known as value categories: lvalue, xvalue, prvalue. There's an overlap between these, so a higher level
More informationIS 0020 Program Design and Software Tools
1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Multiple Inheritance July 26, 2004 22.9 Multiple Inheritance 2 Multiple inheritance Derived class has several base classes Powerful,
More informationException handling. void sophisticatedalgorithm (char* name) { std::ifstream in(name); // using the file for an algorithm
a / p p U / / / Z ] Y R ] R / / a R 3 / S S S S p p handling 36=?3C=ED= +698B5 %+2436587:95
More information