Structured Types. 8. Arrays. collection of components whose organization is characterized by method used to access individual components.

Size: px
Start display at page:

Download "Structured Types. 8. Arrays. collection of components whose organization is characterized by method used to access individual components."

Transcription

1 Structured Types 1 Structured data type: collection of components whose organization is characterized by method used to access individual components. Examples of structured types in C++ array struct union class

2 Definitions 2 Array : sequential list of variables of the same type. Mathematics: a 0 a 1 a 2 a i a n C++: a[0] a[1] a[2] a[i] a[n] a [0] [1][2] [i] [n] Array elements have the same properties as simple variables of the same type. Array elements are operated upon the same as corresponding simple typed variables.

3 Array Declaration 3 The declaration of an array variable must specify the name of the array, the type of element the array is to contain, and the dimension (or size) of the array. The dimension must be a constant or a constant expression. const int BufferSize = 256; const int MaxSize = 12; char Buffer[BufferSize]; // constant integer dimension int DiceFreq[MaxSize - 1]; // constant integer expression, // used as dimension int RollValue = 11; float Payroll[RollValue]; // variable integer // NOT valid - RollValue is not // a constant

4 Indices 4 An array is indexed using the integer data type and indices always start at 0. const int BufferSize = 256; char Buffer[BufferSize]; Buffer[0] = x ; // assigns value to first array element cout << Buffer[132]; // prints value of 133rd array element Logically valid indices for an array range from 0 to N-1, where N is the dimension of the array. char A[7]; stands for A[0], A[1], A[2], A[3], A[4], A[5], and A[6] Logically, there is no A[7]! Memory A[0] A[1] A[2] A[3] A[4] A[5] A[6]

5 Accessing 5 An array is a structured data type which stores multiple values of the same data type. Each value is referenced via an index into the array. Array declaration: const int MaxStudents = 30; int Quiz[MaxStudents]; int Exam[MaxStudents]; int i, Hold, NextQuiz; Array references: Exam[1] = 95; cout << setw(5) << Quiz[5]; NextQuiz = Quiz[i + 1];

6 Aggregate Operations 6 An operation on a data structure as a whole, as opposed to an operation on an individual component of the data structure. Consider the declarations: const int Size = 50; int x[size]; int y[size]; and assume the arrays x[] and y[] have been initialized, which of the following aggregate operations are allowed? Assignment: x = y; Comparison: x = = y; I/O: cout << x; Arithmetic: x + y Return: return x; Parameter: somefunc(x);

7 Implementing Aggregate Operations 7 The operations discussed on the previous slide that are not supported automatically may still be implemented by user-defined code. For example, an equality test could be written as: bool AreEqual = true; for (int index = 0; ( index < Size && AreEqual ); index++) { if (x[index]!= y[index]) AreEqual = false; The standard way to process an array is to write a for loop and use the loop counter as an index into the array; as the loop iterates, the index walks down the array, allowing you to process the array elements in sequence. Note the use of the Boolean variable in the for loop header. This causes the for loop to exit as soon as two unequal elements have been found, improving efficiency at run-time.

8 Array Usage 8 Like other C++ variables, arrays do not contain useful initial values when declared. const int Max = 100; int Height[Max]; for (int i = 0; i < Max; i++) Height [ i ] = 0; A common logical error in processing arrays is exceeding the valid index range: int X[Max]; X[ a ] X[100] will not compile. will compile (according to the Standard). Recall Boolean Short Circuiting: int i = 0 ; while( (i < Max) && (X[i]!= desiredelement) ) { i++;

9 More on Array Indices 9 What happens when a statement uses an array index that is out of bounds? First, there is no automatic checking of array index values at run-time (some languages do provide for this). Consider the code fragment below: const int NumScores = 100; int MaxScore = 25; int Score[NumScores]; for (int i = 0; i <= NumScores; i++) // initialize too many Score [ i ] = 0; On the last pass through the for loop body, the int value 0 will be stored at the (logical) location Score[100]. But what is that, since the only logically valid locations in Score[] would be Score[0] through Score[99]? Score[100] is interpreted as referring to the next int-sized chunk of memory following the last cell of the array, so the value 0 will be stored there whether that makes sense or not.

10 More on Array Indices Consider the possibilities. The memory location Score[100] may: 10 store a variable declared in your program store an instruction that is part of your program (unlikely on modern machines) not be allocated for the use of your program In the first case, the error shown on the previous slide would cause the value of that variable to be altered. Since there is no statement that directly assigns a value to that variable, this effect seems very mysterious when debugging. In the second case, if the altered instruction is ever executed it will have been replaced by a nonsense instruction code. This will (if you are lucky) result in the system killing your program for attempting to execute an illegal instruction. In the third case, the result depends on the operating system you are using. Some operating systems, such as Windows 95/98 do not carefully monitor memory accesses and so your program may corrupt a value that actually belongs to another program (or even the operating system itself). Other operating systems, such as Windows NT or UNIX, will detect that a memory access violation has occurred and suspend or kill your program.

11 Array Initialization at Declaration An array variable may be initialized at the point of declaration: int height[3] = {5, 7, 8; 11 If there are fewer initializers than elements in the array, the remaining elements are automatically initialized to 0. Thus: int height[3] = {0; is equivalent to: int height[3] = {0, 0, 0; and: int n[10] = {-1; explicitly initializes the first array element to -1 and implicitly initializes the other nine elements of the array to 0. Providing too many initializers causes a compile-time error: int height[3] = {5, 7, 8, 9;

12 Array Initialization via a Loop 12 Of course, an array variable also may be initialized via a simple loop: const int MaxScores = 75; double Score[MaxScores]; for (int idx = 0; idx < MaxScores; idx++) { Score[idx] = 0.0; The loop may easily be modified to assign different values to different array elements or to obtain the initial values from a file or a function call. Remember: one of the Deadly Sins of Programming is failure to properly initialize variables. In some problems array bounds errors are often much easier to detect if you initialize your arrays to dummy values that can be distinguished from logically correct values (using the value -1.0 instead of 0.0 above, for instance).

13 Array Elements as Parameters 13 A single array element can be passed as an actual parameter to a function. void Swap(float& a1, float& a2) { // Local data float temp; temp = a1; a1 = a2; a2 = temp; return; Simple float reference parameters To exchange Status[3] and Status[5] inside array Status we invoke swap as: Swap(Status[3], Status[5]); Note well: when passing a single array element, the actual parameter is the array name, with an index. In other words, Status refers to the entire array while Status[k] refers to the single element at index k.

14 Entire Arrays as Parameters 14 Entire arrays can also be passed as parameters. By default arrays are automatically passed using pass-by-reference. Preceding a formal array parameter by the keyword const results in the array being passed by constant reference, the effect being that the actual array parameter cannot be modified by the called function. // Array elements with subscripts ranging from 0 to size - 1 // are summed element by element // Pre: a[i] and b[i] (0 <= i <= size -1) are defined // Post: c[i] = a[i] + b[i] (0 <= i <= size - 1) void AddArray(int size, const float a[], const float b[], float c[]) { for (int i = 0; i < size; i++) c[i] = a[i] + b[i]; // add and store result return; Invoke AddArray as follows: AddArray(MaxSize, X, Y, Z); Note well: when passing an entire array, the actual parameter is the array name, without an index.

15 Arrays as Parameters 15 Calling function data area actual arguments max_size 5 5 Function AddArray data area size array x a[ ] ????? array y array z b[ ] c[ ] local variable i

16 Cautionary Note 16 The equality test code presented earlier can be incorporated into a function, as shown below. Note that there is no way for the function to determine whether the array indices are within logically correct bounds. If the function is passed a value for NumCells that is larger than the dimension of either of the actual array parameters, then memory locations that exist outside the array boundaries will be compared. This type of logical error is extremely difficult to debug. bool AreEqual(const int A[], const int B[], const int NumCells) { for (int index = 0; index < NumCells; index++) { if (A[index]!= B[index]) return false; return true; If global constants for the maximum array size has been defined then the assert() function can be used to check that the array accesses will be safe. For example the following could be placed at the beginning of the function: assert ( (Numcells < MAX_ARRAY_A_SIZE) && (Numcells < MAX_ARRAY_B_SIZE) ) ;

17 C-style Character Strings 17 A string like "Hello" can be thought of as just an array of chars: char String1[6] = Hello ; H e l l o \0 Same effect as: char String1[6] = { H, e, l, l, o, \0 ; The array contains the five characters plus a special string termination character called the NULL character, inserted automatically when the specified array initialization is done. Thus, the dimension of the char array must be one greater than the length of the (longest) string to be stored in the array. It is legal to omit the array dimension, as shown below. In that case, the dimension is automatically set to the length of the initializing string literal plus 1: char String2[] = What s your name? ;

18 Character Strings: input 18 It is possible to use the extraction operator to read a character string into a char array: char string2[20]; cin >> string2; // Reads a string from keyboard into string2; // there is no designation as to the size of the array; // programmer s responsibility to insure that array is // big enough - cin does not check However, this is not the preferred technique; extraction operator string input: skips leading whitespace, then reads consecutive characters until the next whitespace character is encountered, which may not be appropriate. does append a NULL, which is good. does not consider the dimension of the target array, so it may store characters in memory past the end of the array, which is very bad. See the succeeding slides on the family of get( ) functions for a better approach.

19 Character Strings: output 19 const int MAXSTR = 20 ; char string2[maxstr] = Good morning! ; cout << string2; // Outputs string2 to the screen; // there is no designation as to the size of the array; // cout displays the characters until the NULL // character is reached const int MAXSTR = 20 ; char string2[maxstr] = Good morning! ; int i = 0; bool endofstring = false ; endofstring = ( string2[i] == \0 ); while ( (i < MAXSTR) && (!endofstring) ) { cout << setw(1) << string2[i]; // print char i++ ; // count endofstring = ( string2[i] == \0 ); // check Almost equivalent to the above code is the code to the left. Care must be taken to ensure that the code does not produce problems, such as garbage in the output stream or a binary output file, if the string is not terminated by the NULL character.

20 strcat( ) function 20 void strcat(char dest[], char source[]); // see footnote concatenates the character string source onto the end of the character string dest, taking proper care of the NULLs #include <iostream.h> #include <string.h> // for standard C-string functions void main() { const int MAXLINE = 80 ; char a[maxline] = "The quick brown fox"; char b[maxline] = " jumps over the lazy dog"; strcat(a, b); cout << "a contains: " << a << endl; produces the output: a contains: The quick brown fox jumps over the lazy dog ( the return type of these functions aren t really void, but we re not ready to discuss that yet.)

21 strlen( ) function int strlen(char source[]); 21 returns the length of the character string source, excluding the terminating NULL character #include <iostream.h> #include <string.h> void main() { const int MAXLINE = 80 ; char a[maxline] = "The quick brown fox"; int length; length = strlen(a); cout << "The following string has " << length << " characters:" << endl; cout << a << endl; produces the output: The following string has 19 characters: The quick brown fox

22 strcpy( ) function void strcpy(char dest[], char source[]); 22 copies the character string source into the character string dest #include <iostream.h> #include <string.h> void main() { const int MAXLINE = 80 ; char a[maxline] = "The quick brown fox"; char b[maxline] = " jumps over the lazy dog"; strcpy(a, b); cout << a << endl; produces the output: jumps over the lazy dog

23 strcmp( ) function int strcmp(char first[], char second[]); 23 compares the character strings first and second lexicographically, returning: < 0 if first precedes second 0 if first and second are the same > 0 if first follows second The comparison is based on the ASCII code sequence, so upper-case letters precede lower-case letters.

24 strcmp( ) function 24 #include <iostream.h> #include <string.h> void main() { char a[] = Frederick ; char b[] = Freddy ; int k; k = strcmp(a, b); if (k < 0) cout << a << before << b << endl; else if (k == 0) cout << a << equals << b << endl; else // k > 0 cout << b << before << a << endl; produces the output: Freddy before Frederick

25 Character Strings: input (get) 25 To input characters that contain whitespace either the get( ) or getline( ) functions must be used. The get function can be passed a character array and an integer parameter. Reading continues until the int parameter number of characters - 1 has been read or the new line character is encountered. The get( ) function appends a NULL character to the end of the string. ifstream infile; const int FILELENMAX = 51; char filename[filelenmax]; // 50 char name limit cout << "Enter the input file name: "; cin.get(filename, FILELENMAX); cin.ignore(100, \n ); infile.open(filename, ios::nocreate); if (!infile) { cout << "** Can t open input file **" << endl; return EXIT_FAILURE; Note: if a new line character is encountered get( ), does NOT remove the new line character from the input stream. The ignore( ) function can be used to explicitly remove the new line character.

26 Character Strings: input (get) 26 There is yet another variation of the get( ) function which takes three parameters. The third parameter is a char, specifying the stop character (which defaults to a newline when you use the two-parameter get( ) function. ifstream infile; const FILELENMAX = 51 ; Const DEPTLENMAX = 10 ; char Name[FILELENMAX]; char Department[DEPTLENMAX]; // 50 char name limit // 9 char dept limit cin.get(filename, FILELENMAX); cin.ignore(100, \n ); infile.open("employee.dat", ios::nocreate); while (infile) { infile.get(name, FILELENMAX, \t ); infile.ignore(100, \t ); infile.get(department, DEPTLENMAX, ); cout << Name << \t << Department << endl; // read to tab // read to space

27 Character Strings: input (getline) 27 The getline function is similar to the get function for reading a line of input. However the getline function automatically removes the next new line character from the input stream. It does not store the new line character in the string ifstream infile; const FILELENMAX = 51 ; char filename[filelenmax]; // 50 char file name limit cout << "Enter the input file name: "; cin.getline(filename, FILELENMAX); infile.open(filename, ios::nocreate); if (!infile) { cout << "** Can t open input file **" << endl; return EXIT_FAILURE;

28 Parallel Arrays 28 Arrays can contain values of only one type. Parallel arrays can be used to handle related data of different types. Two arrays can be considered parallel if their indexes and entries are logically related. For example, to store an inventory list containing a price and an availability code, two arrays can be declared as follows: const int NUMPARTS = 500; Index (Part #) Price Available I float Price[NUMPARTS]; char Available[NUMPARTS]; O X Assuming the arrays have been initialized, the statement below prints an inventory list. Note that Price[Part] and Available[Part] refer to the same logical item: for (int Part = 0; Part < NumParts; Part++) cout << setw( 5) << Part << setw(10) << setprecision(2) << Price[Part] << setw( 5) << Available[Part] << endl;

29 Array of Arrays 29 The component type of a C++ array may be of any type, even other arrays. char Names [3][8] = {"JOHNSON", // Names is a two dimensional "RUSSELL", // table of characters "KENT"; J O H N S O N \0 1 R U S S E L L \0 2 K E N T \0 Names[2] 3rd name in the list (Remember arrays are indexed from 0) Names[1][4] 5th character of 2nd name This declaration may be thought of in two ways. Names is a two-dimensional array of chars; Names is also a one-dimensional array of C-style character strings.

30 Array of Arrays (cont) 30 int array1[2][3] = { {1, 2, 3, {4, 5, 6 ; int array2[2][3] = { 1, 2, 3, 4, 5 ; int array3[2][3] = { {1, 2, {4 ; If we printed these arrays by rows, we would find the following initializations had taken place: Rows of array1: Rows of array2: Rows of array3: for (int row = 0; row < 2; row++) { for (int col = 0; col < 3; col++) { cout << setw(3) << array1[row][col]; cout << endl;

31 Multi-Dimensional Arrays 31 An array can be declared with multiple dimensions. 2 Dimensional 3 Dimensional double Coord[100][100][100]; Multiple dimensions get difficult to visualize graphically.

32 Multiple Dimensional Arrays as Parameters 32 When passing a two-dimensional array as a parameter, the base address is passed, as is the case with one-dimensional arrays. But now the number of columns in the array parameter must be specified. This is because arrays are stored in row-major order, and the number of columns must be known in order to calculate the location at which each row begins in memory: address of element (r, c) = base address of array + r*(number of elements in a row)*(size of an element) + c*(size of an element) void somefunc(const int TwoD[][NUMCOLS], const int rows) { for (int i = 0; i < rows; i++) { for (int j = 0; j < NUMCOLS; j++) TwoD[i][j] = -1;

CPE Summer 2015 Exam I (150 pts) June 18, 2015

CPE Summer 2015 Exam I (150 pts) June 18, 2015 Name Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. You can assume that there is one

More information

Strings(2) CS 201 String. String Constants. Characters. Strings(1) Initializing and Declaring String. Debzani Deb

Strings(2) CS 201 String. String Constants. Characters. Strings(1) Initializing and Declaring String. Debzani Deb CS 201 String Debzani Deb Strings(2) Two interpretations of String Arrays whose elements are characters. Pointer pointing to characters. Strings are always terminated with a NULL characters( \0 ). C needs

More information

Arrays array array length fixed array fixed length array fixed size array Array elements and subscripting

Arrays array array length fixed array fixed length array fixed size array Array elements and subscripting Arrays Fortunately, structs are not the only aggregate data type in C++. An array is an aggregate data type that lets us access many variables of the same type through a single identifier. Consider the

More information

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points) Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow

More information

Review of Important Topics in CS1600. Functions Arrays C-strings

Review of Important Topics in CS1600. Functions Arrays C-strings Review of Important Topics in CS1600 Functions Arrays C-strings Array Basics Arrays An array is used to process a collection of data of the same type Examples: A list of names A list of temperatures Why

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence

More information

Name Section: M/W T/TH Number Definition Matching (6 Points)

Name Section: M/W T/TH Number Definition Matching (6 Points) Name Section: M/W T/TH Number Definition Matching (6 Points) 1. (6 pts) Match the words with their definitions. Choose the best definition for each word. Event Counter Iteration Counter Loop Flow of Control

More information

Arrays. Lecture 9 COP 3014 Fall October 16, 2017

Arrays. Lecture 9 COP 3014 Fall October 16, 2017 Arrays Lecture 9 COP 3014 Fall 2017 October 16, 2017 Array Definition An array is an indexed collection of data elements of the same type. Indexed means that the array elements are numbered (starting at

More information

Software Design & Programming I

Software Design & Programming I Software Design & Programming I Starting Out with C++ (From Control Structures through Objects) 7th Edition Written by: Tony Gaddis Pearson - Addison Wesley ISBN: 13-978-0-132-57625-3 Chapter 3 Introduction

More information

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords. Chapter 1 File Extensions: Source code (cpp), Object code (obj), and Executable code (exe). Preprocessor processes directives and produces modified source Compiler takes modified source and produces object

More information

SYSC 2006 C Winter String Processing in C. D.L. Bailey, Systems and Computer Engineering, Carleton University

SYSC 2006 C Winter String Processing in C. D.L. Bailey, Systems and Computer Engineering, Carleton University SYSC 2006 C Winter 2012 String Processing in C D.L. Bailey, Systems and Computer Engineering, Carleton University References Hanly & Koffman, Chapter 9 Some examples adapted from code in The C Programming

More information

Array Initialization

Array 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 information

Learning Objectives. Introduction to Arrays. Arrays in Functions. Programming with Arrays. Multidimensional Arrays

Learning Objectives. Introduction to Arrays. Arrays in Functions. Programming with Arrays. Multidimensional Arrays Chapter 5 Arrays Learning Objectives Introduction to Arrays Declaring and referencing arrays For-loops and arrays Arrays in memory Arrays in Functions Arrays as function arguments, return values Programming

More information

Characters, c-strings, and the string Class. CS 1: Problem Solving & Program Design Using C++

Characters, c-strings, and the string Class. CS 1: Problem Solving & Program Design Using C++ Characters, c-strings, and the string Class CS 1: Problem Solving & Program Design Using C++ Objectives Perform character checks and conversions Knock down the C-string fundamentals Point at pointers and

More information

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts Strings and Streams 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++, by Walter

More information

Name Section: M/W T/TH Number Definition Matching (8 Points)

Name Section: M/W T/TH Number Definition Matching (8 Points) Name Section: M/W T/TH Number Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Iteration Counter Event Counter Loop Abstract Step

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.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 information

Definition Matching (10 Points)

Definition Matching (10 Points) Name SOLUTION Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. There are no syntax errors

More information

13 4 Understanding Character Strings

13 4 Understanding Character Strings World Headquarters Jones and Bartlett Publishers Jones and Bartlett Publishers Jones and Bartlett Publishers 40 Tall Pine Drive Canada International Sudbury, MA01776 2406 Nikanna Road Barb House, Barb

More information

CSCI 6610: Intermediate Programming / C Chapter 12 Strings

CSCI 6610: Intermediate Programming / C Chapter 12 Strings ... 1/26 CSCI 6610: Intermediate Programming / C Chapter 12 Alice E. Fischer February 10, 2016 ... 2/26 Outline The C String Library String Processing in C Compare and Search in C C++ String Functions

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty! Chapter 6 - Functions return type void or a valid data type ( int, double, char, etc) name parameter list void or a list of parameters separated by commas body return keyword required if function returns

More information

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

Chapter 7 Array. Array. C++, How to Program

Chapter 7 Array. Array. C++, How to Program Chapter 7 Array C++, How to Program Deitel & Deitel Spring 2016 CISC 1600 Yanjun Li 1 Array Arrays are data structures containing related data items of same type. An array is a consecutive group of memory

More information

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS242 ARRAYS

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS242 ARRAYS Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS242 1 ARRAYS Arrays 2 Arrays Structures of related data items Static entity (same size

More information

Chapter 7: User-Defined Simple Data Types, Namespaces, and the string Type

Chapter 7: User-Defined Simple Data Types, Namespaces, and the string Type Strings Chapter 7: User-Defined Simple Data Types, Namespaces, and the string Type A string is a sequence of characters. Strings in C++ are enclosed in "". Examples: "porkpie" "TVC15" (a 7-character string)

More information

Arrays. Week 4. Assylbek Jumagaliyev

Arrays. Week 4. Assylbek Jumagaliyev Arrays Week 4 Assylbek Jumagaliyev a.jumagaliyev@iitu.kz Introduction Arrays Structures of related data items Static entity (same size throughout program) A few types Pointer-based arrays (C-like) Arrays

More information

Outline. 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. 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 information

FORM 2 (Please put your name and form # on the scantron!!!!)

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam 2: FORM 2 (Please put your name and form # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. Recursive algorithms tend to be less efficient than iterative algorithms. 2. A recursive function

More information

Chapter 8 Arrays and Strings. Objectives. Objectives (cont d.) Introduction. Arrays 12/23/2016. In this chapter, you will:

Chapter 8 Arrays and Strings. Objectives. Objectives (cont d.) Introduction. Arrays 12/23/2016. In this chapter, you will: Chapter 8 Arrays and Strings Objectives In this chapter, you will: Learn about arrays Declare and manipulate data into arrays Learn about array index out of bounds Learn about the restrictions on array

More information

C++ PROGRAMMING SKILLS Part 4: Arrays

C++ PROGRAMMING SKILLS Part 4: Arrays C++ PROGRAMMING SKILLS Part 4: Arrays Outline Introduction to Arrays Declaring and Initializing Arrays Examples Using Arrays Sorting Arrays: Bubble Sort Passing Arrays to Functions Computing Mean, Median

More information

The C++ Language. Arizona State University 1

The C++ Language. Arizona State University 1 The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

CS150 Intro to CS I. Fall Fall 2017 CS150 - Intro to CS I 1

CS150 Intro to CS I. Fall Fall 2017 CS150 - Intro to CS I 1 CS150 Intro to CS I Fall 2017 Fall 2017 CS150 - Intro to CS I 1 Character Arrays Reading: pp.554-568 Fall 2017 CS150 - Intro to CS I 2 char Arrays Character arrays can be used as special arrays called

More information

Model Viva Questions for Programming in C lab

Model 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 information

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010 CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011 Lectures 1-22 Moaaz Siddiq Asad Ali Latest Mcqs MIDTERM EXAMINATION Spring 2010 Question No: 1 ( Marks: 1 ) - Please

More information

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows Unti 4: C Arrays Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type An array is used to store a collection of data, but it is often more useful

More information

Declaration of Statically-Allocated Arrays

Declaration of Statically-Allocated Arrays Declaration of Statically-Allocated Arrays Arrays in C 1 In C, an array is simply a fixed-sized aggregation of a list of cells, each of which can hold a single values (objects). The number of cells in

More information

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

C Style Strings. Lecture 11 COP 3014 Spring March 19, 2018

C Style Strings. Lecture 11 COP 3014 Spring March 19, 2018 C Style Strings Lecture 11 COP 3014 Spring 2018 March 19, 2018 Recap Recall that a C-style string is a character array that ends with the null character Character literals in single quotes a, \n, $ string

More information

Preprocessor Directives

Preprocessor Directives C++ By 6 EXAMPLE Preprocessor Directives As you might recall from Chapter 2, What Is a Program?, the C++ compiler routes your programs through a preprocessor before it compiles them. The preprocessor can

More information

Exercise 1.1 Hello world

Exercise 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 information

LECTURE 15. String I/O and cstring library

LECTURE 15. String I/O and cstring library LECTURE 15 String I/O and cstring library RECAP Recall that a C-style string is a character array that ends with the null character. Character literals in single quotes: 'a', '\n', '$ String literals in

More information

CSC 2400: Computer Systems. Arrays and Strings in C

CSC 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 information

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): 1. The declaration below declares three pointer variables of type pointer to double that is

More information

2 nd Week Lecture Notes

2 nd Week Lecture Notes 2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous

More information

Engineering Problem Solving with C++, Etter

Engineering Problem Solving with C++, Etter Engineering Problem Solving with C++, Etter Chapter 6 Strings 11-30-12 1 One Dimensional Arrays Character Strings The string Class. 2 C style strings functions defined in cstring CHARACTER STRINGS 3 C

More information

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators Objectives Chapter 4: Control Structures I (Selection) In this chapter, you will: Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical (Boolean)

More information

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

UEE1302 (1102) F10 Introduction to Computers and Programming (I)

UEE1302 (1102) F10 Introduction to Computers and Programming (I) Computational Intelligence on Automation Lab @ NCTU UEE1302 (1102) F10 Introduction to Computers and Programming (I) Programming Lecture 07 Arrays: Basics and Multi-dimensional Arrays Learning Objectives

More information

For example, let s say we define an array of char of size six:

For example, let s say we define an array of char of size six: Arrays in C++ An array is a consecutive group of memory locations that all have the same name and the same type. To refer to a particular location, we specify the name and then the positive index into

More information

BITG 1113: Array (Part 1) LECTURE 8

BITG 1113: Array (Part 1) LECTURE 8 BITG 1113: Array (Part 1) LECTURE 8 1 1 LEARNING OUTCOMES At the end of this lecture, you should be able to: 1. Describe the fundamentals of arrays 2. Describe the types of array: One Dimensional (1 D)

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

String Class in C++ When the above code is compiled and executed, it produces result something as follows: cin and strings

String Class in C++ When the above code is compiled and executed, it produces result something as follows: cin and strings String Class in C++ The standard C++ library provides a string class type that supports all the operations mentioned above, additionally much more functionality. We will study this class in C++ Standard

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

Character Functions & Manipulators Arrays in C++ CS 16: Solving Problems with Computers I Lecture #10

Character Functions & Manipulators Arrays in C++ CS 16: Solving Problems with Computers I Lecture #10 Character Functions & Manipulators Arrays in C++ CS 16: Solving Problems with Computers I Lecture #10 Ziad Matni Dept. of Computer Science, UCSB Lecture Outline Useful character manipulators & functions

More information

CS201 Spring2009 Solved Sunday, 09 May 2010 14:57 MIDTERM EXAMINATION Spring 2009 CS201- Introduction to Programming Question No: 1 ( Marks: 1 ) - Please choose one The function of cin is To display message

More information

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d. Chapter 4: Control Structures I (Selection) In this chapter, you will: Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical (Boolean)

More information

Procedural Programming & Fundamentals of Programming

Procedural Programming & Fundamentals of Programming Procedural Programming & Fundamentals of Programming Lecture 3 - Summer Semester 2018 & Joachim Zumbrägel What we know so far... Data type serves to organize data (in the memory), its possible values,

More information

BITG 1233: Array (Part 1) LECTURE 8 (Sem 2, 17/18)

BITG 1233: Array (Part 1) LECTURE 8 (Sem 2, 17/18) BITG 1233: Array (Part 1) LECTURE 8 (Sem 2, 17/18) 1 LEARNING OUTCOMES At the end of this lecture, you should be able to: 1. Describe the fundamentals of arrays 2. Describe the types of array: One Dimensional

More information

A structure is an aggregate data type which contains a fixed number of heterogeneous components.

A structure is an aggregate data type which contains a fixed number of heterogeneous components. Structures 1 Definition: A structure is an aggregate data type which contains a fixed number of heterogeneous components. Structure components are termed fields or members, each with a unique name. Each

More information

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called.

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Chapter-12 FUNCTIONS Introduction A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Types of functions There are two types

More information

8. Characters, Strings and Files

8. 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 information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 04 Programs with IO and Loop We will now discuss the module 2,

More information

what are strings today: strings strings: output strings: declaring and initializing what are strings and why to use them reading: textbook chapter 8

what are strings today: strings strings: output strings: declaring and initializing what are strings and why to use them reading: textbook chapter 8 today: strings what are strings what are strings and why to use them reading: textbook chapter 8 a string in C++ is one of a special kind of data type called a class we will talk more about classes in

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Memory, Arrays & Pointers

Memory, Arrays & Pointers 1 Memory, Arrays & Pointers Memory int main() { char c; int i,j; double x; c i j x 2 Arrays Defines a block of consecutive cells int main() { int i; int a[3]; i a[0] a[1] a[2] Arrays - the [ ] operator

More information

9.1 The Array Data Type. Data Structures Arrays and Structs. Arrays. Arrays. Array Declaration. Arrays. Array elements have a common name

9.1 The Array Data Type. Data Structures Arrays and Structs. Arrays. Arrays. Array Declaration. Arrays. Array elements have a common name 9.1 The Array Data Type Data Structures Arrays and Structs Chapter 9 Array elements have a common name The array as a whole is referenced through the common name Array elements are of the same type the

More information

ONE DIMENSIONAL ARRAYS

ONE DIMENSIONAL ARRAYS LECTURE 14 ONE DIMENSIONAL ARRAYS Array : An array is a fixed sized sequenced collection of related data items of same data type. In its simplest form an array can be used to represent a list of numbers

More information

CS 31 Review Sheet. Tau Beta Pi - Boelter Basics 2. 2 Working with Decimals 2. 4 Operators 3. 6 Constants 3.

CS 31 Review Sheet. Tau Beta Pi - Boelter Basics 2. 2 Working with Decimals 2. 4 Operators 3. 6 Constants 3. CS 31 Review Sheet Tau Beta Pi - Boelter 6266 Contents 1 Basics 2 2 Working with Decimals 2 3 Handling Strings and Numbers with stdin/stdout 3 4 Operators 3 5 Common Mistakes/Misconceptions 3 6 Constants

More information

Come and join us at WebLyceum

Come and join us at WebLyceum Come and join us at WebLyceum For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc Go to http://www.weblyceum.com and click Register In Case of any Problem Contact Administrators Rana Muhammad

More information

Week 5. Muhao Chen.

Week 5. Muhao Chen. Week 5 Muhao Chen Email: muhaochen@ucla.edu 1 Outline Multi-dimensional arrays C-string 2 Multi-dimensional Array An array of arrays int xy[3][4] = { {1,2,3,4}, {5,6,7,8}, {4,3,2,1} }; 1 2 3 4 5 6 7 8

More information

Pointers, Dynamic Data, and Reference Types

Pointers, Dynamic Data, and Reference Types Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple

More information

Chapter 10. Arrays and Strings

Chapter 10. Arrays and Strings Christian Jacob Chapter 10 Arrays and Strings 10.1 Arrays 10.2 One-Dimensional Arrays 10.2.1 Accessing Array Elements 10.2.2 Representation of Arrays in Memory 10.2.3 Example: Finding the Maximum 10.2.4

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

CSC 2400: Computer Systems. Arrays and Strings in C

CSC 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 information

Consider the following statements. string str1 = "ABCDEFGHIJKLM"; string str2; After the statement str2 = str1.substr(1,4); executes, the value of str2 is " ". Given the function prototype: float test(int,

More information

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ. C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,

More information

C++ Programming. Arrays and Vectors. Chapter 6. Objectives. Chiou. This chapter introduces the important topic of data structures collections

C++ Programming. Arrays and Vectors. Chapter 6. Objectives. Chiou. This chapter introduces the important topic of data structures collections C++ Programming Chapter 6 Arrays and Vectors Yih-Peng Chiou Room 617, BL Building (02) 3366-3603 3603 ypchiou@cc.ee.ntu.edu.tw Photonic Modeling and Design Lab. Graduate Institute of Photonics and Optoelectronics

More information

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): 1. If a function has default arguments, they can be located anywhere

More information

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011

Agenda. 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 information

CS1100 Introduction to Programming

CS1100 Introduction to Programming CS1100 Introduction to Programming Sorting Strings and Pointers Madhu Mutyam Department of Computer Science and Engineering Indian Institute of Technology Madras Lexicographic (Dictionary) Ordering Badri

More information

Today in CS161. Lecture #12 Arrays. Learning about arrays. Examples. Graphical. Being able to store more than one item using a variable

Today in CS161. Lecture #12 Arrays. Learning about arrays. Examples. Graphical. Being able to store more than one item using a variable Today in CS161 Lecture #12 Arrays Learning about arrays Being able to store more than one item using a variable Examples Tic Tac Toe board as an array Graphical User interaction for the tic tac toe program

More information

7.1 Optional Parameters

7.1 Optional Parameters Chapter 7: C++ Bells and Whistles A number of C++ features are introduced in this chapter: default parameters, const class members, and operator extensions. 7.1 Optional Parameters Purpose and Rules. Default

More information

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team Question No: 1 ( Marks: 2 ) Write a declaration statement for an array of 10

More information

Abstract Data Type (ADT) & ARRAYS ALGORITHMS & DATA STRUCTURES I COMP 221

Abstract Data Type (ADT) & ARRAYS ALGORITHMS & DATA STRUCTURES I COMP 221 Abstract Data Type (ADT) & ARRAYS ALGORITHMS & DATA STRUCTURES I COMP 221 Abstract Data Type (ADT) Def. a collection of related data items together with an associated set of operations e.g. whole numbers

More information

Programming. C++ Basics

Programming. C++ Basics Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++

More information

7.1. Chapter 7: Arrays Hold Multiple Values. Array - Memory Layout. A single variable can only hold one value. Declared using [] operator:

7.1. Chapter 7: Arrays Hold Multiple Values. Array - Memory Layout. A single variable can only hold one value. Declared using [] operator: Chapter 7: 7.1 Arrays Arrays Hold Multiple Values Arrays Hold Multiple Values Array - Memory Layout A single variable can only hold one value int test; 95 Enough memory for 1 int What if we need to store

More information

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency Introduction Fundamentals Declaring arrays Indexing arrays Initializing arrays Arrays and functions Multidimensional arrays Sorting and algorithm efficiency An array is a sequence of values of the same

More information

In this chapter, you will learn about: An Array Type for Strings. The Standard string Class. Vectors. Introduction Computer Science 1 CS 23021

In this chapter, you will learn about: An Array Type for Strings. The Standard string Class. Vectors. Introduction Computer Science 1 CS 23021 Chapter 8 In this chapter, you will learn about: An Array Type for Strings The Standard string Class Vectors The C Language Representation of Strings (C-Strings) The C-String Variable: Array of Characters

More information

C++ Quick Guide. Advertisements

C++ Quick Guide. Advertisements C++ Quick Guide Advertisements Previous Page Next Page C++ is a statically typed, compiled, general purpose, case sensitive, free form programming language that supports procedural, object oriented, and

More information

C strings. (Reek, Ch. 9) 1 CS 3090: Safety Critical Programming in C

C strings. (Reek, Ch. 9) 1 CS 3090: Safety Critical Programming in C C strings (Reek, Ch. 9) 1 Review of strings Sequence of zero or more characters, terminated by NUL (literally, the integer value 0) NUL terminates a string, but isn t part of it important for strlen()

More information

C++ Arrays. Arrays: The Basics. Areas for Discussion. Arrays: The Basics Strings and Arrays of Characters Array Parameters

C++ Arrays. Arrays: The Basics. Areas for Discussion. Arrays: The Basics Strings and Arrays of Characters Array Parameters C++ Arrays Areas for Discussion Strings and Joseph Spring/Bob Dickerson School of Computer Science Operating Systems and Computer Networks Lecture Arrays 1 Lecture Arrays 2 To declare an array: follow

More information

Getting started with C++ (Part 2)

Getting started with C++ (Part 2) Getting started with C++ (Part 2) CS427: Elements of Software Engineering Lecture 2.2 11am, 16 Jan 2012 CS427 Getting started with C++ (Part 2) 1/22 Outline 1 Recall from last week... 2 Recall: Output

More information

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 6: One Dimensional Array

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 6: One Dimensional Array Lesson Outcomes At the end of this chapter, student should be able to: Define array Understand requirement of array Know how to access elements of an array Write program using array Know how to pass array

More information

Piyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class

Piyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class C++ IO C++ IO All I/O is in essence, done one character at a time For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Concept: I/O operations act on streams

More information

Exam 3 Chapters 7 & 9

Exam 3 Chapters 7 & 9 Exam 3 Chapters 7 & 9 CSC 2100-002/003 29 Mar 2017 Read through the entire test first BEFORE starting Put your name at the TOP of every page The test has 4 sections worth a total of 100 points o True/False

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

Copyright 2003 Pearson Education, Inc. Slide 1

Copyright 2003 Pearson Education, Inc. Slide 1 Copyright 2003 Pearson Education, Inc. Slide 1 Chapter 11 Strings and Vectors Created by David Mann, North Idaho College Copyright 2003 Pearson Education, Inc. Slide 2 Overview An Array Type for Strings

More information