STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY
|
|
- Clare Copeland
- 5 years ago
- Views:
Transcription
1 STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY
2 Objectives Declaration of 1-D and 2-D Arrays Initialization of arrays Inputting array elements Accessing array elements Manipulation of 1-D array elements (Sum, Product, Average, Maximum/Minimum, Linear search) Manipulation of 2- D array elements (Sum of row elements, column elements, diagonal elements, finding maximum/minimum values)
3 Array An Array is a series of elements of the same data type placed in contiguous memory locations referred by a common name. The elements of array are referred by their Subscript number or Index number which starts from zero.
4 One Dimensional Array One Dimensional or Single Dimensional Arrays comprises of definite number of homogeneous elements Syntax to declare 1-D Array is : datatype NameOfArray [ SizeOfArray] ; Example: int Num[5]; // Num can store 5 integers char Str[10]; // Str can store a single string Num[0] Num[1] Num[2] Num[3] Num[4] H A N S R A J \0 Str[0] Str[1] Str[2] Str[3] Str[4] Str[5] Str[6] Str[7] Str[8] Str[9]
5 Memory Usage of 1-D Array Memory Consumed by 1D Array = Size of Data Type X No. of Elements Example: int Num[5]; = 2 Byte X 5 Elements = 10 Bytes char Str[10]; = 1 Byte X 10 Elements = 10 Bytes float Amt[3]; = 4 Byte X 3 Elements = 12 Bytes
6 Two Dimensional Array Two Dimensional comprises of an Array of elements each of which is itself an Array Syntax to declare 2-D Array is : Example: datatype NameOfArray [ NoOfRows] [ NoOfColumns] ; int arr[4][4]; ROW=0 COL=0 COL=1 COL=2 COL=3 43 arr[0] [0] 22 arr[0] [1] 16 arr[0] [2] 34 arr[0] [3] ROW=1 67 arr[1] [0] 26 arr[1] [1] 98 arr[1] [2] 12 arr[1] [3] ROW=2 54 arr[2] [0] 24 arr[2] [1] 89 arr[2] [2] 64 arr[2] [3] ROW=3 23 arr[3] [0] 34 arr[3] [1] 78 arr[3] [2] 29 arr[3] [3]
7 Memory Usage of 2-D Array Memory consumed by 2D Array = Size of Data Type X No. of Rows X No. of Columns Example: int Num[4][3] ; = 2 Byte X 4 Rows X 3 Cols = 24 Bytes char Str[5][10]; = 1 Byte X 5 Rows X 10 Cols = 50 Bytes float Amt[[5][4]; = 4 Byte X 5 Rows X 4 Cols = 80 Bytes
8 Initialization of 1-D Array Elements At the time of declaration array elements can be initialized as follows: int Num[4] = { 54,65,72,34 }; char Str[4] = { C, +, +, \0 }; Num[0] Num[1] Num[2] Num[3] char Str[4] = C++ ; Note: int A[5] = {21, 45, 67, 43, 23, 87, 90, 100}; // Error because number of values between braces {} is greater than the array size int A[5] = {34, 56, 22}; // If less initializers, the remaining elements are set to default values i.e A[3] = 0, A[4] = 0 Unsized Array Initialization of 1-D Arrays : If you skip the size of the array in the array initialization statement, compiler automatically creates an array big enough to hold all initializers present in the statement. int Arr[] = { 500,600,700 }; char Str[] = Hello ; Arr[0] Arr[1] Arr[2] C + + \0 Str[0] Str[1] Str[2] Str[3] H e l l o \0 Str[0] Str[1] Str[2] Str[3] Str[4] Str[5]
9 Initialization of 2-D Array Elements Example: int arr[2][3]={43,22,16,67,26,98}; // can store a 2x3 Matrix of Integers char arr[2][5]={ AMAN, RAMA }; // can store 2 Strings of maximum 5 chars each Unsized Array Initialization of 2-D Arrays : 2-D Arrays can be initialized in an unsized manner, but you can skip the Row size only and the Column size needs to be mentioned in the declaration. int arr [][2]={500,600,700,800,900}; COL=0 COL=1 COL=2 Advantage of Unsized Array Initialization 900 ROW=2 arr[2] [0] It allows you to change the array content i.e lengthen or shorten the number of elements without resizing the Array ROW=0 ROW=1 ROW=0 ROW=1 43 arr[0] [0] 67 arr[1] [0] ROW=0 ROW=1 COL=0 500 arr[0] [0] 700 arr[1] [0] 22 arr[0] [1] 26 arr[1] [1] COL=1 600 arr[0] [1] 800 arr[1] [1] 0 arr[2] [1] 16 arr[0] [2] 98 arr[1] [2] COL=0 COL=1 COL=2 COL=3 COL=4 A arr[0] [0] R arr[1] [0] M arr[0] [1] A arr[1] [1] A arr[0] [2] M arr[1] [2] N arr[0] [3] A arr[1] [3] \0 arr[0] [4] \0 arr[1] [4]
10 Inputting Array Elements in 1-D Arrays #define MAX 5 Accepting input in 1-D integer array: int num[max]; //can store MAX integers for(int i=0;i<max;i++) cin>>num[i]; Num[0] Num[1] Num[2] Num[3] Num[4] Accepting input in 1-D character array: char arr[max]; //can store only one string containing MAX-1 chars cin>>arr; or gets(arr); Str[0] Str[1] Str[2] Str[3] Str[4]
11 Inputting Array Elements in 2-D Integer Arrays #define MAX 4 Accepting input in 2-D integer array: int arr[max][max]; //can store a matrix of MAX * MAX integers //Row wise input: for(int i=0;i<max;i for(int j=0;j<max;j++) cin>>arr[i][j]; //Column wise input: for(int j=0;j<max;j++) for(int i=0;i<max;i++) cin>>arr[i][j]; Row 0 Row 1 Row 2 Row 3 Row 0 Row 1 Row 2 Col 0 Col 1 Col 2 Col 3 Col 0 Col 1 Col 2 Col 3 Row 3
12 Inputting Array Elements in 2-D Character Arrays #define MAX 4 Accepting input in 2-D character array: char arr[max][max]; //can store MAX strings - each containing MAX-1 chars for(int i=0;i<max;i++) gets(arr[i]); String 0 String 1 S arr[0] [0] M arr[1] [0] A arr[0] [1] A arr[1] [1] T arr[0] [2] T arr[1] [2] \0 arr[0] [3] \0 arr[1] [3] String 2 X arr[2] [0] A arr[2] [1] T arr[2] [2] \0 arr[2] [3] String 3 C arr[3] [0] A arr[3] [1] T arr[3] [2] \0 arr[3] [3]
13 Assignment Statement Array elements can be assigned a new value during the execution of the program. Example: int A[5]; A[3] = 4; A[1] = A[3] + 10; A[4] = A[1] + A[3]; A[2] = 7 A[4]; A[0] = A[1] + A[4]; A[0] A[1] A[2] A[3] A[4] A[0] A[1] A[2] A[3] A[4] A[0] A[1] A[2] A[3] A[4] A[0] A[1] A[2] A[3] A[4] A[0] A[1] A[2] A[3] A[4]
14 Passing 1-D arrays to functions Arrays are always automatically passed by reference. Thus when you specify the name of a 1-D integer array as an argument to a function, only the starting address of the array i.e the address of the 0 th element is received by the function. This function has no means to find out how many elements are present in the array, since integer arrays are not terminated by null character \0 Therefore you need to pass a 2 nd separate argument to the called function which is the size of the array. Function Prototype should be: returndatatype function_name ( datatype arrayname[], int NoOfElements );
15 Sum of elements of 1-D array #include <iostream.h> #define MAX 10 int SUM (int[], int); //prototype void main() { int A[MAX], N, Ans; cout << Enter the number of locations ; cin >> N; for (int I = 0; I <N; I++) { cout << Enter data in A[ << I << ] = ; cin >> A[I]; } Ans = SUM (A, N); cout << Sum of elements = << Ans; } int SUM( int Arr[], int n) { int S = 0; for (int I = 0; I < n; I++) S = S + Arr[I]; return S; }
16 Product of elements of 1-D array #include <iostream.h> #define MAX 10 int PROD (int[], int); void main() { int A[MAX], N, Ans; cout << Enter the number of locations ; cin >>N; for (int I = 0; I < N; I++) { cout << Enter data in A[ << I << ] = ; cin >> A[I]; } Ans = PROD (A, N); cout << Product of elements = << Ans; } int PROD( int Arr[], int n) { int P = 1; for (int I = 0; I < n; I++) P = P * Arr[I]; return P; }
17 #include <iostream.h> #define MAX 10 float Average (int[], int); //prototype void main() { int A[MAX], n; float Ans; cout << Enter the number of locations ; cin >> n; for (int I = 0; I < N; I++) { cout << Enter data in A[ << I << ] = ; cin >> A[I]; } Ans = Average (A,N); cout << Average of elements = << Ans; } float Average ( int Arr[], int n) { int S = 0; for (int I = 0; I < n; I++) S = S + Arr[I]; return float(s)/n; } Average of elements of 1-D array
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 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 informationTo 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 informationPOINTERS - Pointer is a variable that holds a memory address of another variable of same type. - It supports dynamic allocation routines. - It can improve the efficiency of certain routines. C++ Memory
More informationCMPS 221 Sample Final
Name: 1 CMPS 221 Sample Final 1. What is the purpose of having the parameter const int a[] as opposed to int a[] in a function declaration and definition? 2. What is the difference between cin.getline(str,
More informationExam 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 informationChapter 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 informationBITG 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 informationBITG 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 informationArrays and Strings. Arash Rafiey. September 12, 2017
September 12, 2017 Arrays Array is a collection of variables with the same data type. Arrays Array is a collection of variables with the same data type. Instead of declaring individual variables, such
More informationModule 6: Array in C
1 Table of Content 1. Introduction 2. Basics of array 3. Types of Array 4. Declaring Arrays 5. Initializing an array 6. Processing an array 7. Summary Learning objectives 1. To understand the concept of
More informationCS201 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 informationChapter 01 Arrays Prepared By: Dr. Murad Magableh 2013
Chapter 01 Arrays Prepared By: Dr. Murad Magableh 2013 One Dimensional Q1: Write a program that declares two arrays of integers and fills them from the user. Then exchanges their values and display the
More informationSyntax to define a Structure: struct structurename { datatype membername1; datatype membername2;... } ; For Example:
STRUCTURE IN C++ 1 A Structure is a collection of variables of different data types under one name. A structure defines a new user defined data type for your current program using which items of different
More informationArrays. int Data [8] [0] [1] [2] [3] [4] [5] [6] [7]
Arrays Arrays deal with storage of data, which can be processed later. Arrays are a series of elements (variables) of the same type placed consecutively in memory that can be individually referenced by
More informationArrays in C++ Instructor: Andy Abreu
Arrays in C++ Instructor: Andy Abreu Reason behind the idea When we are programming, often we have to process a large amount of information. We can do so by creating a lot of variables to keep track of
More informationCS201- 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 informationAn array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type.
Data Structures Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous
More informationComputer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];
Arrays An array is a collection of two or more adjacent memory cells, called array elements. Array is derived data type that is used to represent collection of data items. C Array is a collection of data
More informationLesson 7. Reading and Writing a.k.a. Input and Output
Lesson 7 Reading and Writing a.k.a. Input and Output Escape sequences for printf strings Source: http://en.wikipedia.org/wiki/escape_sequences_in_c Escape sequences for printf strings Why do we need escape
More informationUNIT 2 ARRAYS 2.0 INTRODUCTION. Structure. Page Nos.
UNIT 2 ARRAYS Arrays Structure Page Nos. 2.0 Introduction 23 2.1 Objectives 24 2.2 Arrays and Pointers 24 2.3 Sparse Matrices 25 2.4 Polynomials 28 2.5 Representation of Arrays 30 2.5.1 Row Major Representation
More informationGabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming
1 2 3 CMPE 013/L and Strings Gabriel Hugh Elkaim Spring 2013 4 Definition are variables that can store many items of the same type. The individual items known as elements, are stored sequentially and are
More informationCS201- Introduction to Programming Current Quizzes
CS201- Introduction to Programming Current Quizzes Q.1 char name [] = Hello World ; In the above statement, a memory of characters will be allocated 13 11 12 (Ans) Q.2 A function is a block of statements
More informationC++ 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 informationPrinciples of Programming. Chapter 6: Arrays
Chapter 6: Arrays In this chapter, you will learn about Introduction to Array Array declaration Array initialization Assigning values to array elements Reading values from array elements Simple Searching
More informationCAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE
CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE a) Mention any 4 characteristic of the object car. Ans name, colour, model number, engine state, power b) What
More informationQUIZ: loops. Write a program that prints the integers from -7 to 15 (inclusive) using: for loop while loop do...while loop
QUIZ: loops Write a program that prints the integers from -7 to 15 (inclusive) using: for loop while loop do...while loop QUIZ: loops Write a program that prints the integers from -7 to 15 using: for
More informationMaltepe University Computer Engineering Department. BİL 133 Algorithms and Programming. Chapter 8: Arrays
Maltepe University Computer Engineering Department BİL 133 Algorithms and Programming Chapter 8: Arrays What is an Array? Scalar data types use a single memory cell to store a single value. For many problems
More informationC for Engineers and Scientists: An Interpretive Approach. Chapter 10: Arrays
Chapter 10: Arrays 10.1 Declaration of Arrays 10.2 How arrays are stored in memory One dimensional (1D) array type name[expr]; type is a data type, e.g. int, char, float name is a valid identifier (cannot
More informationWrite a C program using arrays and structure
03 Arrays and Structutes 3.1 Arrays Declaration and initialization of one dimensional, two dimensional and character arrays, accessing array elements. (10M) 3.2 Declaration and initialization of string
More informationChapter 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 informationHow to declare an array in C?
Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous values.
More informationLecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)
Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) In this lecture, you will: Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of
More informationArrays in C. Rab Nawaz Jadoon DCS. Assistant Professor. Department of Computer Science. COMSATS IIT, Abbottabad Pakistan
Arrays in C DCS COMSATS Institute of Information Technology Rab Nawaz Jadoon Assistant Professor COMSATS IIT, Abbottabad Pakistan Introduction to Computer Programming (ICP) Array C language provides a
More informationLecture 12. We have already used strings. Strings. Hello Class is a string.
Lecture 12 Strings We have already used strings cout
More informationObjectives. Chapter 8 Arrays and Strings. Objectives (cont d.) Introduction 12/14/2014. In this chapter, you will:
Objectives Chapter 8 Arrays and Strings 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 informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science Department Lecture 3: C# language basics Lecture Contents 2 C# basics Conditions Loops Methods Arrays Dr. Amal Khalifa, Spr 2015 3 Conditions and
More informationARRAYS(II Unit Part II)
ARRAYS(II Unit Part II) Array: An array is a collection of two or more adjacent cells of similar type. Each cell in an array is called as array element. Each array should be identified with a meaningful
More informationFORM 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 informationKingdom 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 informationFORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):
FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): 1. When you attach & after the datatype in the parameter list of a function, the variable following
More informationArrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur
Arrays CS10001: Programming & Data Structures Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Array Many applications require multiple data items that have common
More informationFOR Loop. FOR Loop has three parts:initialization,condition,increment. Syntax. for(initialization;condition;increment){ body;
CLASSROOM SESSION Loops in C Loops are used to repeat the execution of statement or blocks There are two types of loops 1.Entry Controlled For and While 2. Exit Controlled Do while FOR Loop FOR Loop has
More informationCSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011
CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011 Date: 01/18/2011 (Due date: 01/20/2011) Name and ID (print): CHAPTER 6 USER-DEFINED FUNCTIONS I 1. The C++ function pow has parameters.
More informationArray. Prepared By - Rifat Shahriyar
Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types
More informationArrays. Defining arrays, declaration and initialization of arrays. Designed by Parul Khurana, LIECA.
Arrays Defining arrays, declaration and initialization of arrays Introduction Many applications require the processing of multiple data items that have common characteristics (e.g., a set of numerical
More informationHomework #3 CS2255 Fall 2012
Homework #3 CS2255 Fall 2012 MULTIPLE CHOICE 1. The, also known as the address operator, returns the memory address of a variable. a. asterisk ( * ) b. ampersand ( & ) c. percent sign (%) d. exclamation
More informationPointers, Dynamic Data, and Reference Types
Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple
More informationArrays. Example: Run the below program, it will crash in Windows (TurboC Compiler)
1 Arrays General Questions 1. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array? A. The element will be set to 0. B. The compiler would
More informationFORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):
FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. The basic commands that a computer performs are input (get data), output (display result),
More information5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!
FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. Assume that all variables are properly declared. The following for loop executes 20 times.
More informationC++ Arrays. To declare an array in C++, the programmer specifies the type of the elements and the number of elements required by an array as follows
Source: Tutorials Point C++ Arrays C++ Arrays C++ provides a data structure, the array, which stores a fixed-size, sequential collection of elements of the same type An array is used to store a collection
More information2. ARRAYS What is an Array? index number subscrip 2. Write array declarations for the following: 3. What is array initialization?
1 2. ARRAYS 1. What is an Array? Arrays are used to store a set of values of the same type under a single variable name. It is a collection of same type elements placed in contiguous memory locations.
More informationThe University Of Michigan. EECS402 Lecture 05. Andrew M. Morgan. Savitch Ch. 5 Arrays Multi-Dimensional Arrays. Consider This Program
The University Of Michigan Lecture 05 Andrew M. Morgan Savitch Ch. 5 Arrays Multi-Dimensional Arrays Consider This Program Write a program to input 3 ints and output each value and their sum, formatted
More informationArrays. Eng. Mohammed Abdualal
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 9 Arrays
More informationQuiz Start Time: 09:34 PM Time Left 82 sec(s)
Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability
More informationLecture (07) Arrays. By: Dr. Ahmed ElShafee. Dr. Ahmed ElShafee, ACU : Fall 2015, Programming I
Lecture (07) Arrays By: Dr Ahmed ElShafee ١ introduction An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type Instead
More informationCS201 Latest Solved MCQs
Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II
CS313D: ADVANCED PROGRAMMING LANGUAGE Lecture 3: C# language basics II Lecture Contents 2 C# basics Methods Arrays Methods 3 A method: groups a sequence of statement takes input, performs actions, and
More informationArrays. Dr. Madhumita Sengupta. Assistant Professor IIIT Kalyani
Arrays Dr. Madhumita Sengupta Assistant Professor IIIT Kalyani INTRODUCTION An array is a collection of similar data s / data types. The s of the array are stored in consecutive memory locations and are
More informationFor 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 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 informationUNIT-I Fundamental Notations
UNIT-I Fundamental Notations Introduction to Data Structure We know that data are simply values or set of values and information is the processed data. And actually the concept of data structure is much
More informationcast.c /* Program illustrates the use of a cast to coerce a function argument to be of the correct form. */
cast.c /* Program illustrates the use of a cast to coerce a function argument to be of the correct form. */ #include #include /* The above include is present so that the return type
More informationUnit IV & V Previous Papers 1 mark Answers
1 What is pointer to structure? Pointer to structure: Unit IV & V Previous Papers 1 mark Answers The beginning address of a structure can be accessed through the use of the address (&) operator If a variable
More informationReview. Outline. Array Pointer Object-Oriented Programming. Fall 2017 CISC2200 Yanjun Li 1. Fall 2017 CISC2200 Yanjun Li 2
Review Fall 2017 CISC2200 Yanjun Li 1 Outline Array Pointer Object-Oriented Programming Fall 2017 CISC2200 Yanjun Li 2 1 Computer Fall 2017 CISC2200 Yanjun Li 3 Array Arrays are data structures containing
More informationReview. Outline. Array Pointer Object-Oriented Programming. Fall 2013 CISC2200 Yanjun Li 1. Fall 2013 CISC2200 Yanjun Li 2
Review Fall 2013 CISC2200 Yanjun Li 1 Outline Array Pointer Object-Oriented Programming Fall 2013 CISC2200 Yanjun Li 2 1 Array Arrays are data structures containing related data items of same type. An
More information2/3/2018 CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II. Lecture Contents. C# basics. Methods Arrays. Dr. Amal Khalifa, Spr17
CS313D: ADVANCED PROGRAMMING LANGUAGE Lecture 3: C# language basics II Lecture Contents 2 C# basics Methods Arrays 1 Methods : Method Declaration: Header 3 A method declaration begins with a method header
More informationMODULE 3: Arrays, Functions and Strings
MODULE 3: Arrays, Functions and Strings Contents covered in this module I. Using an Array II. Functions in C III. Argument Passing IV. Functions and Program Structure, locations of functions V. Function
More informationGE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004
GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 Functions and Program Structure Today we will be learning about functions. You should already have an idea of their uses. Cout
More informationPointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology
Introduction to C++ Massachusetts Institute of Technology ocw.mit.edu 6.096 Pointers 1 Background 1.1 Variables and Memory When you declare a variable, the computer associates the variable name with a
More informationMultiple 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 information5.2 Defining and Initializing Arrays Statically in the Data Segment
5 Arrays and Files 5.1 Objectives After completing this lab, you will: Define and initialize arrays statically in the data segment Allocate memory dynamically on the heap Compute the memory addresses of
More information6. User Defined Functions I
6 User Defined Functions I Functions are like building blocks They are often called modules They can be put togetherhe to form a larger program Predefined Functions To use a predefined function in your
More informationFORM 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 informationComputers Programming Course 10. Iulian Năstac
Computers Programming Course 10 Iulian Năstac Recap from previous course 5. Values returned by a function A return statement causes execution to leave the current subroutine and resume at the point in
More informationCHAPTER 3 ARRAYS. Dr. Shady Yehia Elmashad
CHAPTER 3 ARRAYS Dr. Shady Yehia Elmashad Outline 1. Introduction 2. Arrays 3. Declaring Arrays 4. Examples Using Arrays 5. Multidimensional Arrays 6. Multidimensional Arrays Examples 7. Examples Using
More informationCHAPTER 4 FUNCTIONS. 4.1 Introduction
CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main
More informationFunctions. Introduction :
Functions Introduction : To develop a large program effectively, it is divided into smaller pieces or modules called as functions. A function is defined by one or more statements to perform a task. In
More informationChapter 2: Introduction to C++
Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++
More informationChapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen
Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley
More informationA First Book of ANSI C Fourth Edition. Chapter 8 Arrays
A First Book of ANSI C Fourth Edition Chapter 8 Arrays Objectives One-Dimensional Arrays Array Initialization Arrays as Function Arguments Case Study: Computing Averages and Standard Deviations Two-Dimensional
More informationarrays review arrays and memory arrays: character array example cis15 advanced programming techniques, using c++ summer 2008 lecture # V.
topics: arrays pointers arrays of objects resources: cis15 advanced programming techniques, using c++ summer 2008 lecture # V.1 some of this lecture is covered in parts of Pohl, chapter 3 arrays review
More informationSample Paper Class XI Subject Computer Sience UNIT TEST II
Sample Paper Class XI Subject Computer Sience UNIT TEST II (General OOP concept, Getting Started With C++, Data Handling and Programming Paradigm) TIME: 1.30 Hrs Max Marks: 40 ALL QUESTIONS ARE COMPULSURY.
More informationPointers. September 13, 2017 Hassan Khosravi / Geoffrey Tien 1
Pointers September 13, 2017 Hassan Khosravi / Geoffrey Tien 1 Multi-dimensional arrays A two-dimensional array is specified using two indices First index denotes the row, second index denotes column int
More informationMultiple 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 informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationTrue or False (14 Points)
Name Number True or False (14 Points) 1. (15 pts) Circle T for true and F for false: T F a) void functions can use the statement return; T F b) Arguments corresponding to value parameters can be variables.
More informationLecture 3 Tao Wang 1
Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers
More informationb. array s first element address c. base address of an array d. all elements of an array e. both b and c 9. An array elements are always stored in a.
UNIT IV 1. Appropriately comment on the following declaration int a[20]; a. Array declaration b. array initialization c. pointer array declaration d. integer array of size 20 2. Appropriately comment on
More informationArrays. 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 informationEE 312 Fall 2017 Midterm 1 October 12, 2017
EE 312 Fall 2017 Midterm 1 October 12, 2017 Name: EID: Recitation time: Recitation TA (circle one): Colin Huy Give clear, legible answers. If you give more than one answer, we will randomly choose one
More informationC++ Arrays. C++ Spring 2000 Arrays 1
C++ Arrays C++ Spring 2000 Arrays 1 C++ Arrays An array is a consecutive group of memory locations. Each group is called an element of the array. The contents of each element are of the same type. Could
More informationUnit 14. Passing Arrays & C++ Strings
1 Unit 14 Passing Arrays & C++ Strings PASSING ARRAYS 2 3 Passing Arrays As Arguments Can we pass an array to another function? YES!! Syntax: Step 1: In the prototype/signature: Put empty square brackets
More informationArrays 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 informationData types. CISC 1600/1610 Computer Science I. Array syntax. Memory allocation. Zero-indexing 4/4/2016. Arrays
4/4/6 CISC 6/6 Computer Science I rrays Professor Daniel Leeds dleeds@fordham.edu JMH 38 Data types Single pieces of information one integer int one symbol char one truth value bool Multiple pieces of
More informationName SECTION: 12:45 2:20. True or False (12 Points)
Name SECION: 12:45 2:20 rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables
More informationIntroduction to Computer Science Midterm 3 Fall, Points
Introduction to Computer Science Fall, 2001 100 Points Notes 1. Tear off this sheet and use it to keep your answers covered at all times. 2. Turn the exam over and write your name next to the staple. Do
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 informationONE 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