Steps of initialisation:

Size: px
Start display at page:

Download "Steps of initialisation:"

Transcription

1 1. a. Arrays in C# are objects and derive from System.Array. They are the simplest collection or data structure in C# and may contain any value or reference type. In fact, an array is the only collection that is part of the System namespace. They are declared with a specific type and they cannot change their size once declared. Steps of declaration: At step (1), a reference variable is created a certain type array. At step (2), space is allocated to store values of certain type. The square brackets [] must be placed after the type in both steps (1) and (2). Only at st ep (2), however, is the actual number of elements placed within the brackets. int[] myarray; // (1) One dimensional array myarray = new int[3]; // (2) int[] myarray = new int[3]; Steps of initialisation: So far, the myarray array has been declared, but each array element has not been explicitly initialized. Therefore, each array element is initialized implicitly to its default value, in this case, 0. It is important to note that if the array type was our Id class instead of int in other words, a reference type instead of a value type then myarray would be an array of references initialized by default to null. Elements in the array, however, can be initialized explicitly in a number of ways. The use of an initializer, as in C/C++ and Java, is often preferred to declare and initialize an array at the same time: int[] myarray={1,3,5}; In this case, the compiler determines the number of integers within the initializer and implicitly creates an array of size 3. In fact, the preceding example is equivalent to this more explicit one: int[] myarray = new int[3] { 1, 3, 5 }; Accessing an array: Elements of an array are accessed by following the array name with an index in square brackets. Bearing in mind that indices begin at 0, myarray[2] accesses the third element. C# supports two kinds of multi-dimensional arrays: rectangular and jagged. Rectangular arrays like matrices have more than one index and have a fixed size for each dimension. The comma (,) separates each dimension in the array declaration as illustrated here: int[,] matrix = new int[2,3]; // 2x3 matrix (6 elements). int[,,] cube = new int[2,3,4]; // 2x3x4 cube (24 elements). Accessing the element at the first row and second column of the matrix is done as follows: matrix[0,1]; // matrix [ <row>, <column> ] Jagged arrays are arrays of arrays where each element is a reference pointing to another array. Unlike rectangular arrays, jagged arrays may have a different size for each dimension. Page 1 of 9

2 In the following example, jaggedmatrix allocates space for eight integer elements, three in the first row and five in the second: int[ ][ ] jaggedmatrix = new int[2][ ]; // An array with 2 arrays (rows). jaggedmatrix[0] = new int[3]; // A row of 3 integers. jaggedmatrix[1] = new int[5]; // A row of 5 integers. Accessing the element at the first row and second column of the jaggedmatrix is done as follows: jaggedmatrix[0][1]; // jaggedmatrix [ <row> ] [ <column> ] Of course, attempting to access jaggedmatrix[0][3] throws an IndexOutOfRangeException. Although access to rectangular arrays is more efficient than access to jagged arrays, the latter is more flexible for cases such as sparse matrices. Nonetheless, dimensions for both rectangular and jagged arrays are fixed. When dimensions must grow or when fixed sizes cannot be determined by the application requirements, collections, which are a far more flexible alternative to multi-dimensional arrays. Related Notes on arrays ARRAYS An array is a collection of elements, all of a specific type. And these elements are stored together in memory. Each element is accessed by an integer index. An array is a fixed collection of same-type data that are stored contiguously and that are accessible by an index. ONE-DIMENSIONAL ARRAY: Arrays of Integers Code snippet to allocates and initializes an integer array of three elements. The array is zerobased. The first element is element zero. Element indexes proceed upwards by one. Initialization. This syntax form is shorter. We use curly brackets to assign element values in one line. This is concise. The length of the array is automatically determined in Illustration c and so in Illustration a and b if size is not specified. Illustration a: int[] values = new int[3];//declare int array. 3 is specifying the size of the array (number of elements). Always specify. It s Invalid to put 3 in the first square brackets values[0] = 5;/* initialising first element to be 5. The value zero in square brackets is the index value. Indexing always starts at zero thus index value = postion-1, 1-1 =0*/ values[1] = 10; /* initialising 2nd element to be 1 (value in square brackets)*/ Page 2 of 9

3 values[2] = 15; /* initialising first element to be index 2 (value in square brackets)*/ Console.WriteLine(values[0]);/*accessing the value at index 0 which is 5 and print it to console*/ Console.WriteLine(values[1]); /*accessing the value at index 1 which is 10 and print Console.WriteLine(values[2]); /*accessing the value at index 2 which is 15 and print Illustration b: int[] values = new int[3] { 5, 10, 15 }; /*declaration and initialisation and specifying the size in square brackets after new int. You can also not specify the size in this case since you have initialised i.e leave the square brackets empty*/ Console.WriteLine(values[0]);/*accessing the value at index 0 which is 5 and print it to console*/ Console.WriteLine(values[1]); /*accessing the value at index 1 which is 10 and print Console.WriteLine(values[2]); /*accessing the value at index 2 which is 15 and print Illustration c: int[] values = { 5, 10, 15 }; /*declaration and initialisation, simplest way Console.WriteLine(values[0]);/*accessing the value at index 0 which is 5 and print it to console*/ Console.WriteLine(values[1]); /*accessing the value at index 1 which is 10 and print Console.WriteLine(values[2]); /*accessing the value at index 2 which is 15 and print Arrays of strings string[] ferns = new string[4];// declare and specify the size of the array (number of elements) i.e 4 ferns[0] = "Psilotopsida";//initialising the value at index 0 to Psilotopsida ferns[1] = "Equisetopsida";//initialising the value at index 1 to Equisetopsida ferns[2] = "Marattiopsida";//initialising the value at index 2 to Marattiopsida ferns[3] = "Polypodiopsida";//initialising the value at index 3 to Polypodiopsida Console.WriteLine(ferns[0]);//accessing the value at index 0 and printing it Console.WriteLine(ferns[1]);//accessing the value at index 1 and printing it Console.WriteLine(ferns[2]);//accessing the value at index 2 and printing it Console.WriteLine(ferns[3]);//accessing the value at index 3 and printing it Page 3 of 9

4 string[] ferns = new string[4] { "Psilotopsida", "Equisetopsida", "Marattiopsida", "Polypodiopsida" };/*declaration and initialistion, four elements. Specify or not specify the size*/ Console.WriteLine(ferns[0]);//accessing the value at index 0 and printing it Console.WriteLine(ferns[1]);//accessing the value at index 1 and printing it Console.WriteLine(ferns[2]);//accessing the value at index 2 and printing it Console.WriteLine(ferns[3]);//accessing the value at index 3 and printing it string[] ferns = { "Psilotopsida", "Equisetopsida", "Marattiopsida", "Polypodiopsida" };/*declaration and initialistion, four elements. Always leave the square brackets empty. Console.WriteLine(ferns[0]);//accessing the value at index 0 and printing it Console.WriteLine(ferns[1]);//accessing the value at index 1 and printing it Console.WriteLine(ferns[2]);//accessing the value at index 2 and printing it Console.WriteLine(ferns[3]);//accessing the value at index 3 and printing it MULTI-DIMENSIONAL ARRAY (SIZE 2,3 N) C# Jagged Arrays Data comes in various shapes. Sometimes the shape is uneven. With jagged arrays, we can store efficiently many rows of varying lengths. Important:Jagged arrays have different performance characteristics. Indexing jagged arrays is fast. Allocating them is somewhat slow. Illustration a: // Declare local jagged array with 3 rows(always specify# of rows). The number of columns are not specified since they might vary or specify to make them fixed. int[][] jagged = new int[3][]; // Set first row: Create a new array in the jagged array, and assign it. jagged[0] = new int[2];//first row consists of two elements(first column and second column i.e index 0 and 1 respectively) jagged[0][0] = 1;//first row first column store the value 1 i.e at index 0 for row and index 0 jagged[0][1] = 2;//first row second column store the value 2 i.e at index 0 for row and index 1 // Set second row jagged[1] = new int[3];// second row consists of 3 elements Page 4 of 9

5 jagged[1][0] = 3;//second row first column store the value 3 i.e at index 1 for row and index 0 jagged[1][1] = 4;//second row second column store the value 4 i.e at index 1 for row and index 1 jagged[1][2] = 5;//second row third column store the value 3 i.e at index 1 for row and index 2 // Set third row jagged[2] = new int[4];//third row consists of 4 elements jagged[2][0] = 6;//third row first column stores the value 6 i.e at index 2 for row and index 0 jagged[2][1] = 7;//third row second column stores the value 7 i.e at index 2 for row and index 1 jagged[2][2] = 8;//third row third column stores the value 8 i.e at index 2 for row and index 2 jagged[2][3] = 9;//third row fourth column stores the value 9 i.e at index 2 for row and index 3 Console.WriteLine(jagged[0][0]);//accessing the value at index 0 for row and index 0 for Console.WriteLine(jagged[0][1]);//accessing the value at index 0 for row and index 1 for Console.WriteLine(jagged[1][0]);//accessing the value at index 1 for row and index 0 for Console.WriteLine(jagged[1][1]);//accessing the value at index 1 for row and index 1 for Console.WriteLine(jagged[1][2]);//accessing the value at index 1 for row and index 2 for Console.WriteLine(jagged[2][0]);//accessing the value at index 2 for row and index 0 for Console.WriteLine(jagged[2][1]);//accessing the value at index 2 for row and index 1 for Console.WriteLine(jagged[2][2]);//accessing the value at index 2 for row and index 2 for Console.WriteLine(jagged[2][3]);//accessing the value at index 2 for row and index 3 for Console.ReadLine(); Illustration b: // Declare local jagged array with 3 rows(always specify# of rows). The number of columns are not specified since they might vary or specify to make them fixed. int[][] jagged = new int[3][]; jagged[0] = new int[2] {1,2};//first row initialised with two elements;using array initializer jagged[1] = new int[3] {3,4,5};//second row initialised with 3 elements jagged[2] = new int[4] {6,7,8,9};//third row initialised with 4 elements Console.WriteLine(jagged[0][0]);//accessing the value at index 0 for row and index 0 in that row and printing it Page 5 of 9

6 Console.WriteLine(jagged[0][1]);//accessing the value at index 0 for row and index 1 in that row and printing it Console.WriteLine(jagged[1][0]);//accessing the value at index 1 for row and index 0 in that row and printing it Console.WriteLine(jagged[1][1]);//accessing the value at index 1 for row and index 1 in that row and printing it Console.WriteLine(jagged[1][2]);//accessing the value at index 1 for row and index 2 in that row and printing it Console.WriteLine(jagged[2][0]);//accessing the value at index 2 for row and index 0 in that row and printing it Console.WriteLine(jagged[2][1]);//accessing the value at index 2 for row and index 1 in that row and printing it Console.WriteLine(jagged[2][2]);//accessing the value at index 2 for row and index 2 in that row and printing it Console.WriteLine(jagged[2][3]);//accessing the value at index 2 for row and index 3 in that row and printing it Console.ReadLine(); // Create a new array in the jagged array, and assign it. int[,,] threedimensional = new int[3, 5, 4]; threedimensional[0, 0, 0] = 1; threedimensional[0, 1, 0] = 2; threedimensional[0, 2, 0] = 3; threedimensional[0, 3, 0] = 4; threedimensional[0, 4, 0] = 5; threedimensional[1, 1, 1] = 2; threedimensional[2, 2, 2] = 3; threedimensional[2, 2, 3] = 4; int[,] numbers = new int[3, 2] { {1, 2}, {3, 4}, {5, 6} }; string[,] siblings = new string[2, 2] { {"Mike","Amy"}, {"Mary","Albert"} }; You can omit the size of the array, like this: int[,] numbers = new int[,] { {1, 2}, {3, 4}, {5, 6} }; string[,] siblings = new string[,] { {"Mike","Amy"}, {"Mary","Albert"} }; You can also omit the new operator if an initializer is provided, like this: int[,] numbers = { {1, 2}, {3, 4}, {5, 6} }; string[,] siblings = { {"Mike", "Amy"}, {"Mary", "Albert"} }; Page 6 of 9

7 int[,] numbers = new int[3, 2] { {1, 2}, {3, 4}, {5, 6} }; string[,] siblings = new string[2, 2] { {"Mike","Amy"}, {"Mary","Albert"} }; You can omit the size of the array, like this: int[,] numbers = new int[,] { {1, 2}, {3, 4}, {5, 6} }; string[,] siblings = new string[,] { {"Mike","Amy"}, {"Mary","Albert"} }; You can also omit the new operator if an initializer is provided, like this: int[,] numbers = { {1, 2}, {3, 4}, {5, 6} }; string[,] siblings = { {"Mike", "Amy"}, {"Mary", "Albert"} }; b. Boxing is the process of implicitly casting a value-type variable or literal into a reference type. In other words, it allows value types to be treated as objects. This is done by creating an optimized temporary reference type that refers to the value type. Boxing a value via explicit casting is legal but unnecessary. int i = 2; object o=i; //Implicit casting (or boxing).// Implicit conversion object p = (object)i; // Explicit casting (unnecessary). On the other hand, it is not possible to unbox a reference type into a value type without an explicit cast. The intent must be clear from the compiler s point of view. object o;... short s = (short)o;// Unboxing, Explicit conversion The ability to treat value types as objects bridges the gap that exists in most programming languages. For example, a Stack class can provide push and pop methods that take and return value and reference objects: Page 7 of 9

8 c. Page 8 of 9

9 Page 9 of 9

High Institute of Computer Science & Information Technology Term : 1 st. El-Shorouk Academy Acad. Year : 2013 / Year : 2 nd

High Institute of Computer Science & Information Technology Term : 1 st. El-Shorouk Academy Acad. Year : 2013 / Year : 2 nd El-Shorouk Academy Acad. Year : 2013 / 2014 High Institute of Computer Science & Information Technology Term : 1 st Year : 2 nd Computer Science Department Object Oriented Programming Section (1) Arrays

More information

Arrays. Defining arrays, declaration and initialization of arrays. Designed by Parul Khurana, LIECA.

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

CS 230 Programming Languages

CS 230 Programming Languages CS 230 Programming Languages 11 / 20 / 2015 Instructor: Michael Eckmann Questions/comments? Chapter 6 Arrays Pointers Today s Topics We all know what arrays are. Design issues Legal types for subscripts

More information

11. Arrays. For example, an array containing 5 integer values of type int called foo could be represented as:

11. Arrays. For example, an array containing 5 integer values of type int called foo could be represented as: 11. Arrays An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier. That means that, for example,

More information

Chapter 6: Using Arrays

Chapter 6: Using Arrays Chapter 6: Using Arrays Declaring an Array and Assigning Values to Array Array Elements A list of data items that all have the same data type and the same name Each item is distinguished from the others

More information

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Data Types, Variables and Arrays OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani Identifiers in Java Identifiers are the names of variables, methods, classes, packages and interfaces. Identifiers must

More information

Chapter 8 :: Composite Types

Chapter 8 :: Composite Types Chapter 8 :: Composite Types Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright 2016 Elsevier 1 Chapter08_Composite_Types_4e - Tue November 21, 2017 Records (Structures) and Variants

More information

Array Structure. In C#, arrays can be declared as fixed length or dynamic. A fixed length array can store a predefined number of items.

Array Structure. In C#, arrays can be declared as fixed length or dynamic. A fixed length array can store a predefined number of items. Array Structure Programming C# is a new self-taught series of articles, in which I demonstrate various topics of C# language in a simple step by step tutorial format. Arrays are probably one of the most

More information

IT 374 C# and Applications/ IT695 C# Data Structures

IT 374 C# and Applications/ IT695 C# Data Structures IT 374 C# and Applications/ IT695 C# Data Structures Module 2.5: Methods A Deeper Look Xianrong (Shawn) Zheng Spring 2017 1 Outline static Methods, static Variables, and Class Math Methods with Multiple

More information

Visual C# Instructor s Manual Table of Contents

Visual C# Instructor s Manual Table of Contents Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

More information

Advanced Programming C# Lecture 10. dr inż. Małgorzata Janik

Advanced Programming C# Lecture 10. dr inż. Małgorzata Janik Advanced Programming C# Lecture 10 dr inż. Małgorzata Janik majanik@if.pw.edu.pl Winter Semester 2017/2018 Project (part II) Project part II Date: 18.12.2017 (next week!) Prepare the presentation that

More information

Computer Programming: C++

Computer Programming: C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming: C++ Experiment #7 Arrays Part II Passing Array to a Function

More information

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types COMP-202 Unit 6: Arrays Introduction (1) Suppose you want to write a program that asks the user to enter the numeric final grades of 350 COMP-202

More information

Chapter 6 part 1. Data Types. (updated based on 11th edition) ISBN

Chapter 6 part 1. Data Types. (updated based on 11th edition) ISBN Chapter 6 part 1 Data Types (updated based on 11th edition) ISBN 0-321 49362-1 Chapter 6 Topics Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative

More information

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

Programming for Engineers Iteration

Programming for Engineers Iteration Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

In Java we have the keyword null, which is the value of an uninitialized reference type

In Java we have the keyword null, which is the value of an uninitialized reference type + More on Pointers + Null pointers In Java we have the keyword null, which is the value of an uninitialized reference type In C we sometimes use NULL, but its just a macro for the integer 0 Pointers are

More information

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain Duhok Polytechnic University Amedi Technical Institute/ IT Dept. By Halkawt Rajab Hussain 2016-04-02 Overview. C# program structure. Variables and Constant. Conditional statement (if, if/else, nested if

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Arrays. Comp Sci 1570 Introduction to C++ Array basics. arrays. Arrays as parameters to functions. Sorting arrays. Random stuff

Arrays. Comp Sci 1570 Introduction to C++ Array basics. arrays. Arrays as parameters to functions. Sorting arrays. Random stuff and Arrays Comp Sci 1570 Introduction to C++ Outline and 1 2 Multi-dimensional and 3 4 5 Outline and 1 2 Multi-dimensional and 3 4 5 Array declaration and An array is a series of elements of the same type

More information

Arrays, Strings and Collections

Arrays, Strings and Collections Arrays Arrays can be informally defined as a group of variables containing values of the same type and that in some way or another they are related. An array has a fixed size that is defined before the

More information

PROGRAMMAZIONE I A.A. 2017/2018

PROGRAMMAZIONE I A.A. 2017/2018 PROGRAMMAZIONE I A.A. 2017/2018 ARRAYS ARRAYS An array contains objects of a given type, stored consecutively in a continuous memory block. The individual objects are called the elements of an array. The

More information

Lecture 5: Arrays. A way to organize data. MIT AITI April 9th, 2005

Lecture 5: Arrays. A way to organize data. MIT AITI April 9th, 2005 Lecture 5: Arrays A way to organize data MIT AITI April 9th, 2005 1 What are Arrays? An array is a series of compartments to store data. Essentially a block of variables. In Java, arrays can only hold

More information

Symbol Tables Symbol Table: In computer science, a symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is

More information

CS453 Arrays in Java in general

CS453 Arrays in Java in general Plan for the day - - Arrays in general -- Array descriptors -- Type checking for arrays -- Code gen for arrays CS453 Arrays in Java in general CS453 Lecture Arrays 1 Arrays An array is a collection of

More information

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1 Data Structure using C++ Lecture 04 Reading Material Data Structures and algorithm analysis in C++ Chapter. 3 3.1, 3.2, 3.2.1 Summary Infix to Postfix Example 1: Infix to Postfix Example 2: Postfix Evaluation

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that

More information

Java Primer 1: Types, Classes and Operators

Java Primer 1: Types, Classes and Operators Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

More information

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette COMP 250: Java Programming I Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette Variables and types [Downey Ch 2] Variable: temporary storage location in memory.

More information

Programming for Engineers Arrays

Programming for Engineers Arrays Programming for Engineers Arrays ICEN 200 Spring 2018 Prof. Dola Saha 1 Array Ø Arrays are data structures consisting of related data items of the same type. Ø A group of contiguous memory locations that

More information

Arrays and Collections. C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies

Arrays and Collections. C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies 7 Arrays and Collections C# Programming: From Problem Analysis to Program Design 2nd Edition David McDonald, Ph.D. Director of Emerging Technologies Chapter Objectives Learn array basics Declare arrays

More information

A First Book of ANSI C Fourth Edition. Chapter 8 Arrays

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

Memory and Pointers written by Cathy Saxton

Memory and Pointers written by Cathy Saxton Memory and Pointers written by Cathy Saxton Basic Memory Layout When a program is running, there are three main chunks of memory that it is using: A program code area where the program itself is loaded.

More information

Types II. Hwansoo Han

Types II. Hwansoo Han Types II Hwansoo Han Arrays Most common and important composite data types Homogeneous elements, unlike records Fortran77 requires element type be scalar Elements can be any type (Fortran90, etc.) A mapping

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #43. Multidimensional Arrays

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #43. Multidimensional Arrays Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #43 Multidimensional Arrays In this video will look at multi-dimensional arrays. (Refer Slide Time: 00:03) In

More information

Advanced Computer Programming

Advanced Computer Programming Hazırlayan Yard. Doç. Dr. Mehmet Fidan ARRAYS A group of data with same type stored under one variable. It is assumed that elements in that group are ordered in series. In C# language arrays are has System.Array

More information

1B1a Arrays. Arrays. Indexing. Naming arrays. Why? Using indexing. 1B1a Lecture Slides. Copyright 2003, Graham Roberts 1

1B1a Arrays. Arrays. Indexing. Naming arrays. Why? Using indexing. 1B1a Lecture Slides. Copyright 2003, Graham Roberts 1 Ba Arrays Arrays A normal variable holds value: An array variable holds a collection of values: 4 Naming arrays An array has a single name, so the elements are numbered or indexed. 0 3 4 5 Numbering starts

More information

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - XVIII March 23 rd, 2006 1 Roadmap Arrays Pointers Lists Files and I/O 2 1 Arrays Two layout strategies for arrays Contiguous elements Row pointers Row pointers

More information

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

Arrays and ArrayLists. David Greenstein Monta Vista High School

Arrays and ArrayLists. David Greenstein Monta Vista High School Arrays and ArrayLists David Greenstein Monta Vista High School Array An array is a block of consecutive memory locations that hold values of the same data type. Individual locations are called array s

More information

C# and Java. C# and Java are both modern object-oriented languages

C# and Java. C# and Java are both modern object-oriented languages C# and Java C# and Java are both modern object-oriented languages C# came after Java and so it is more advanced in some ways C# has more functional characteristics (e.g., anonymous functions, closure,

More information

FRAC: Language Reference Manual

FRAC: Language Reference Manual FRAC: Language Reference Manual Justin Chiang jc4127 Kunal Kamath kak2211 Calvin Li ctl2124 Anne Zhang az2350 1. Introduction FRAC is a domain-specific programming language that enables the programmer

More information

C++ Lecture 5 Arrays. CSci 588: Data Structures, Algorithms and Software Design.

C++ Lecture 5 Arrays. CSci 588: Data Structures, Algorithms and Software Design. C++ Lecture 5 Arrays CSci 588: Data Structures, Algorithms and Software Design http://www.cplusplus.com/doc/tutorial/arrays/ All material not from online sources copyright Travis Desell, 2013 Overview

More information

Introduction To C#.NET

Introduction To C#.NET Introduction To C#.NET Microsoft.Net was formerly known as Next Generation Windows Services(NGWS).It is a completely new platform for developing the next generation of windows/web applications. However

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

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved. Data structures Collections of related data items. Discussed in depth in Chapters 16 21. Array objects Data

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

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

Memory Allocation in C

Memory Allocation in C Memory Allocation in C When a C program is loaded into memory, it is organized into three areas of memory, called segments: the text segment, stack segment and heap segment. The text segment (also called

More information

Array. Array Declaration:

Array. Array Declaration: Array Arrays are continuous memory locations having fixed size. Where we require storing multiple data elements under single name, there we can use arrays. Arrays are homogenous in nature. It means and

More information

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University 9/5/6 CS Introduction to Computing II Wayne Snyder Department Boston University Today: Arrays (D and D) Methods Program structure Fields vs local variables Next time: Program structure continued: Classes

More information

Graphs. The ultimate data structure. graphs 1

Graphs. The ultimate data structure. graphs 1 Graphs The ultimate data structure graphs 1 Definition of graph Non-linear data structure consisting of nodes & links between them (like trees in this sense) Unlike trees, graph nodes may be completely

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Last Class. Introduction to arrays Array indices Initializer lists Making an array when you don't know how many values are in it

Last Class. Introduction to arrays Array indices Initializer lists Making an array when you don't know how many values are in it Last Class Introduction to arrays Array indices Initializer lists Making an array when you don't know how many values are in it public class February4{ public static void main(string[] args) { String[]

More information

JME Language Reference Manual

JME Language Reference Manual JME Language Reference Manual 1 Introduction JME (pronounced jay+me) is a lightweight language that allows programmers to easily perform statistic computations on tabular data as part of data analysis.

More information

Programming in C and C++

Programming in C and C++ Programming in C and C++ 5. C++: Overloading, Namespaces, and Classes Dr. Neel Krishnaswami University of Cambridge (based on notes from and with thanks to Anil Madhavapeddy, Alan Mycroft, Alastair Beresford

More information

Array. Prepared By - Rifat Shahriyar

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

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming Exam 1 Prep Dr. Demetrios Glinos University of Central Florida COP3330 Object Oriented Programming Progress Exam 1 is a Timed Webcourses Quiz You can find it from the "Assignments" link on Webcourses choose

More information

Graphs. The ultimate data structure. graphs 1

Graphs. The ultimate data structure. graphs 1 Graphs The ultimate data structure graphs 1 Definition of graph Non-linear data structure consisting of nodes & links between them (like trees in this sense) Unlike trees, graph nodes may be completely

More information

CS 211. Project 5 Infix Expression Evaluation

CS 211. Project 5 Infix Expression Evaluation CS 211 Project 5 Infix Expression Evaluation Part 1 Create you own Stack Class Need two stacks one stack of integers for the operands one stack of characters for the operators Do we need 2 Stack Classes?

More information

Fall Semester (081) Dr. El-Sayed El-Alfy Computer Science Department King Fahd University of Petroleum and Minerals

Fall Semester (081) Dr. El-Sayed El-Alfy Computer Science Department King Fahd University of Petroleum and Minerals INTERNET PROTOCOLS AND CLIENT-SERVER PROGRAMMING Client SWE344 request Internet response Fall Semester 2008-2009 (081) Server Module 2.1: C# Programming Essentials (Part 1) Dr. El-Sayed El-Alfy Computer

More information

Organization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science

Organization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science Organization of Programming Languages CS320/520N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects and

More information

Run-Time Data Structures

Run-Time Data Structures Run-Time Data Structures Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers, it is used for:

More information

CSC Web Programming. Introduction to JavaScript

CSC Web Programming. Introduction to JavaScript CSC 242 - Web Programming Introduction to JavaScript JavaScript JavaScript is a client-side scripting language the code is executed by the web browser JavaScript is an embedded language it relies on its

More information

Object-Oriented Programming for Scientific Computing

Object-Oriented Programming for Scientific Computing Object-Oriented Programming for Scientific Computing Dynamic Memory Management Ole Klein Interdisciplinary Center for Scientific Computing Heidelberg University ole.klein@iwr.uni-heidelberg.de 2. Mai 2017

More information

OCA Java SE 7 Programmer I Certification Guide By Mela Gupta. Arrays

OCA Java SE 7 Programmer I Certification Guide By Mela Gupta. Arrays 1 OCA Java SE 7 Programmer I Certification Guide By Mela Gupta In the OCA Java SE 7 programmer exam, you ll be asked many questions on how to create, modify, and delete String, StringBuilder, arrays, and

More information

C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5

C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5 C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5 1. Pointers As Kernighan and Ritchie state, a pointer is a variable that contains the address of a variable. They have been

More information

Introduction to C++/CLI 3. What C++/CLI can do for you 6 The rationale behind the new syntax Hello World in C++/CLI 13

Introduction to C++/CLI 3. What C++/CLI can do for you 6 The rationale behind the new syntax Hello World in C++/CLI 13 contents preface xv acknowledgments xvii about this book xix PART 1 THE C++/CLI LANGUAGE... 1 1 Introduction to C++/CLI 3 1.1 The role of C++/CLI 4 What C++/CLI can do for you 6 The rationale behind the

More information

C# Fundamentals. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh

C# Fundamentals. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh C# Fundamentals Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh Semester 1 2018/19 H-W. Loidl (Heriot-Watt Univ) F20SC/F21SC 2018/19

More information

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lesson 04 Arrays What are Arrays? An array is a series of compartments to store data. Essentially a block of

More information

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Lesson 06 Arrays MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Array An array is a group of variables (called elements or components) containing

More information

Introduce C# as Object Oriented programming language. Explain, tokens,

Introduce C# as Object Oriented programming language. Explain, tokens, Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation

More information

CPSC 3740 Programming Languages University of Lethbridge. Data Types

CPSC 3740 Programming Languages University of Lethbridge. Data Types Data Types A data type defines a collection of data values and a set of predefined operations on those values Some languages allow user to define additional types Useful for error detection through type

More information

Arrays: Higher Dimensional Arrays. CS0007: Introduction to Computer Programming

Arrays: Higher Dimensional Arrays. CS0007: Introduction to Computer Programming Arrays: Higher Dimensional Arrays CS0007: Introduction to Computer Programming Review If the == operator has two array variable operands, what is being compared? The reference variables held in the variables.

More information

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.

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

Java Overview An introduction to the Java Programming Language

Java Overview An introduction to the Java Programming Language Java Overview An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/

More information

Data Structure. Recitation IV

Data Structure. Recitation IV Data Structure Recitation IV Topic Java Generics Java error handling Stack Lab 2 Java Generics The following code snippet without generics requires casting: List list = new ArrayList(); list.add("hello");

More information

FOR Loop. FOR Loop has three parts:initialization,condition,increment. Syntax. for(initialization;condition;increment){ body;

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

Summer May 18, 2010

Summer May 18, 2010 Summer 2010 to Department of Computer Science Engineering York University Toronto May 18, 2010 1 / 46 What have we done last time? to Basic information about testing: Black- Glass-box tests Rom tests Regression

More information

A brief introduction to C programming for Java programmers

A brief introduction to C programming for Java programmers A brief introduction to C programming for Java programmers Sven Gestegård Robertz September 2017 There are many similarities between Java and C. The syntax in Java is basically

More information

(Refer Slide Time 01:41 min)

(Refer Slide Time 01:41 min) Programming and Data Structure Dr. P.P.Chakraborty Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture # 03 C Programming - II We shall continue our study of

More information

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

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

Arrays. Lecture 11 CGS 3416 Spring March 6, Lecture 11CGS 3416 Spring 2017 Arrays March 6, / 19

Arrays. Lecture 11 CGS 3416 Spring March 6, Lecture 11CGS 3416 Spring 2017 Arrays March 6, / 19 Arrays Lecture 11 CGS 3416 Spring 2017 March 6, 2017 Lecture 11CGS 3416 Spring 2017 Arrays March 6, 2017 1 / 19 Arrays Definition: An array is an indexed collection of data elements of the same type. Indexed

More information

Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition. Chapter 7 Basic Semantics Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

More information

CSC 211 Intermediate Programming. Arrays & Pointers

CSC 211 Intermediate Programming. Arrays & Pointers CSC 211 Intermediate Programming Arrays & Pointers 1 Definition An array a consecutive group of memory locations that all have the same name and the same type. To create an array we use a declaration statement.

More information

Object-Oriented Principles and Practice / C++

Object-Oriented Principles and Practice / C++ Object-Oriented Principles and Practice / C++ Alice E. Fischer June 17, 2013 OOPP / C++ Lecture 9... 1/37 Abstract Classes Multiple Inheritance Template Example Casts Handling Circularly Dependent Classes

More information

COMP6700/2140 Data and Types

COMP6700/2140 Data and Types COMP6700/2140 Data and Types Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU February 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February

More information

Question Points Score

Question Points Score CS 453 Introduction to Compilers Midterm Examination Spring 2009 March 12, 2009 75 minutes (maximum) Closed Book You may use one side of one sheet (8.5x11) of paper with any notes you like. This exam has

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

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

C++ C and C++ C++ fundamental types. C++ enumeration. To quote Bjarne Stroustrup: 5. Overloading Namespaces Classes

C++ C and C++ C++ fundamental types. C++ enumeration. To quote Bjarne Stroustrup: 5. Overloading Namespaces Classes C++ C and C++ 5. Overloading Namespaces Classes Alastair R. Beresford University of Cambridge Lent Term 2007 To quote Bjarne Stroustrup: C++ is a general-purpose programming language with a bias towards

More information

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15 Table of Contents 1 INTRODUCTION... 1 2 IF... 1 2.1 BOOLEAN EXPRESSIONS... 3 2.2 BLOCKS... 3 2.3 IF-ELSE... 4 2.4 NESTING... 5 3 SWITCH (SOMETIMES KNOWN AS CASE )... 6 3.1 A BIT ABOUT BREAK... 7 4 CONDITIONAL

More information

Casting in C++ (intermediate level)

Casting in C++ (intermediate level) 1 of 5 10/5/2009 1:14 PM Casting in C++ (intermediate level) Casting isn't usually necessary in student-level C++ code, but understanding why it's needed and the restrictions involved can help widen one's

More information

EEE-425 Programming Languages (2013) 1

EEE-425 Programming Languages (2013) 1 2 Namespaces Classes Fields Properties Methods Attributes Events Interfaces (contracts) Methods Properties Events Control Statements if, else, while, for, switch foreach Additional Features Operation Overloading

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time

More information

Heap, Variables, References, and Garbage. CS152. Chris Pollett. Oct. 13, 2008.

Heap, Variables, References, and Garbage. CS152. Chris Pollett. Oct. 13, 2008. Heap, Variables, References, and Garbage. CS152. Chris Pollett. Oct. 13, 2008. Outline. Dynamic Allocation. Variables and Constants. Aliases and Problems. Garbage. Introduction. On Wednesday, we were talking

More information

Question And Answer.

Question And Answer. Q.1 What would be the output of the following program? using System; namespaceifta classdatatypes static void Main(string[] args) inti; Console.WriteLine("i is not used inthis program!"); A. i is not used

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages CSE 307: Principles of Programming Languages Variables and Constants R. Sekar 1 / 22 Topics 2 / 22 Variables and Constants Variables are stored in memory, whereas constants need not be. Value of variables

More information