NCS 301 DATA STRUCTURE USING C
|
|
- Gertrude Wilkinson
- 6 years ago
- Views:
Transcription
1 NCS 301 DATA STRUCTURE USING C Unit-1 Part-3 Arrays Hammad Mashkoor Lari Assistant Professor Allenhouse Institute of Technology Introduction Array is a contiguous memory of homogeneous elements. Arrays can store multiple values which can be referenced by a single name Array name is actually a pointer to the first location of memory block allocated to name of array. No bound checking concept for arrays in C. Subject Notes by Hammad Lari 1
2 One dimensional Array One subscript specification is needed Syntax:- Datatype var_name [Expression]; //subscript should be a integer value Example:- Int num[7]; Index Num[0] 22 Num[1] 30 Num[2] 2 Data Size = (upper bound lower bound ) + 1 Size of array num=(6-0)+1=7 Size in bytes=size of array X size of (base type ) Size in bytes=7 X 2=14 Num[3] 5 Num[4] 76 Num[5] 8 Num[6] 34 Initialization One Dimensional Array ANSI C allows automatic array variables to be initialized in declarations by constant initializers. The initializers are specified within braces and separated by commas. Example: Int ex[10]= 12, 23, 9, 17, 16, 49 ; Char word[10]= h, e, l, l, o, \0 ; If there are not enough initializers for whole array the remaining elements of array are initialized to zero. Note:-initializations are not assignment statements, they are declarations that allocate and initialize memory. Subject Notes by Hammad Lari 2
3 Accessing One Dimensional Array Individual elements of array can be accessed using following syntax: Array_name[index or subscript]; Example: Num[1]=90; Program: Int a[10],i; For (i=0;i<=9;i++) Scanf( %d,&a[i]); For(i=0;i<=9;i++) Printf( %d,a[i]); Implementation of One Dimensional Array in memory Address of a particular element in a 1-D array is given by relation: No of required Address of element a[k]=b+w*k element in array(index) Example: Base address B=2000 and each element of array occupies 4 bytes then 5 th element of 1D array will be: Size of each element of array Address of element a[5]= *5= = 2020 Subject Notes by Hammad Lari 3
4 Passing arrays to function Arrays like other simple variables can be passed to function. Arrays are by default passed to function by call by reference method because array name is itself a pointer to the first memory location of the array. But we can also pass individual array elements through call by value method. Program: For (i=0;i<=9;i++) Scanf( %d,&a[i]); Sum=funarray(a,9); Printf( %d,sum); Int funarray(int p[],int n) Int s=0,i=0; For(i=0;i<=n-1;i++) S=s+p[i]; Return s; Insertion in 1D Insertion can be done in two ways 1. Insertion at end of array(easily if space enough to accommodate) 2. Insertion at required position-elements must be moved downwards to new location. i v a[0] 1 a[1] 5 a[2] 7 a[3] 6 a[4] 22 a[5] 90 a[6] 0 a[7] 0 a[8] 0 a[9] 0 Position for 20 i v a[0] 1 a[1] 5 a[2] 7 a[3] 6 a[4] a[5] 22 a[6] 90 a[7] 0 a[8] 0 a[9] 0 i v a[0] 1 a[1] 5 a[2] 7 a[3] 6 a[4] 20 a[5] 22 a[6] 90 a[7] 0 a[8] 0 a[9] 0 Subject Notes by Hammad Lari 4
5 Algorithm 1. [Initialize the value of i] set i=len 2. Repeat for i=len down to pos 1. [shift elements down by 1 position] 2. Set a[i+1]=a[i] 3. [end of loop] 3. [insert element at required position] 1. Set a[pos]=num 4. [reset len] set len=len Display the new list of array 6. End a= linear array num= number len= total no of elements pos= position at which num will be inserted Delete from 1D Deleting an element at end of array present no difficulty Deleting element somewhere in middle of array would require to shift all elements to fill the space emptied. i v a[0] 15 a[1] 7 a[2] 20 a[3] 13 a[4] 66 a[5] 90 a[6] 5 a[7] 10 a[8] 50 a[9] 8 i v a[0] 15 a[1] 7 a[2] 20 a[3] 13 a[4] 66 a[5] a[6] 5 a[7] 10 a[8] 50 a[9] 8 i v a[0] 15 a[1] 7 a[2] 20 a[3] 13 a[4] 66 a[5] 5 a[6] 10 a[7] 50 a[8] 8 a[9] Subject Notes by Hammad Lari 5
6 Algorithm 1. Set item= a[pos] 2. Repeat for j=pos to n-1 1. [shift elements 1 position upward] 2. Set a[j]=a[j+1] 3. [end of loop] 4. reset n=n-1 3. Display the new list of array 4. End Traversing of Array It means access to all elements of array. Algorithm 1. Let LB be the lower bound and UB be the upper bound of linear array a. 2. [initialize counter] set i at lower bound LB 3. Repeat for i=lb to UB 1. visit element] display a[i] 2. [End of loop] 4. Exit Subject Notes by Hammad Lari 6
7 Merging two Arrays Combining elements of two arrays to form a new array. First copy all elements of one array into a third empty array and then copy all elements of other array into third array. If sorting is needed you can sort resultant array or sort during merging(its more efficient). i v Array c Array b c[0] 10 Array a i v c[1] 14 i v b[0] 10 c[2] 16 a[0] 10 b[1] 17 c[3] 17 a[1] 17 b[2] 20 c[4] 19 a[2] 20 b[3] 25 c[5] 20 a[3] 25 c[6] 25 a[4] 50 c[7] 30 a[5] 100 c[8] 50 c[9] 100 Algorithm 1. Create three arrays a1,a2,a3. 2. Enter the element p and q in ascending order in a1,a2. 3. Initialize m and n (lower bounds to 0) 4. Check if (a1[m]-a2[n] [assign elements of a1 to a3] a3[c]=a1[m++) Set c=c+1 Else [assign elements of a2 to a3] a3[c]=a2[n++] Set c=c+1 [End of If] 5. Assign remaining elements of a1,a2 and a3 6. Display elements of array 3 7. End Subject Notes by Hammad Lari 7
8 Multi Dimensional arrays [0][0] [0][1] [0][2] Int int_array[10]; Int int_array2d[10][10]; Initialization a 2D Array Int array2d[3][3]=1,2,3,4,5,6,7,8,9; Initialization a 3D Array Int array3d[3][3][3]= 1,2,3 4,5,6 7,8,9 10,11,12 13,14,15 16,17,18 19,20,21 22,23,24 25,26,27 ; [1][0] [1][1] [1][2] [2][0] [2][1] [2][2] Array3d[1][2][0]=16; Why? 1-second grid(first grid will be 0) 2-third row 0-first element of that row Implementation of a 2d Array A 2d array can be implemented in a P.L in 2 ways:- 1. Row major implementation 2. Column major implementation Row major implementation Linearization technique(elements of array are reader from keyboard row wise i.e. The complete first row is stored then the complete second row is stored and so on). Example:- a00 a01 a02 a10 a11 a12 a20 a21 a22 Row1 Row2 Row3 Actual Physical Storage vs Matrix form is logical representation of array Subject Notes by Hammad Lari 8
9 Address of elements in Row major Address of element a[i][j]=b +W (n ( i - L1) + ( j - L2)) L1-lower bound of row L2-lower bound of column Example A 2d array defined as a[4..7,-1 3] requires 2 bytes of storage space.calculate address of element at location a[6][2].given base address is 100. Solution Base address B=100 size W=2 bytes L1=4 L2=-1 U1=7 U2=3 i=6,j=2 Base address Size of each array element No of columns n=u2-l2+1= 3-(-1)+1=5 Address of a[6][2] = 100+2(5(6-4)+(2-(-1))) Number of columns(u2-l2) =100+2(5*2+3)= = 126 Column major implementation The complete first column is stored then the complete second column is stored and so on). Example:- a00 a01 a02 a10 a11 a12 a20 a21 a22 Column1 Column 2 Column 3 Address of element in Row Column major Major implementation implementation Address of element a[i][j]= B + W (m (j L2) + ( i L1)) Where m is number of rows (U1-L1) Example:-a[-20 20,10 35] requires 1 bytes of storage.b=500.find a[0][30] U1-L1+1=20-(-20)+1=41 Address of a[0][30]=500+1(41(30-10)+(0-(-20))) =500+1(41*20+20)=500+1(840)=1340 Subject Notes by Hammad Lari 9
10 Pointers and 1D Arrays Pointer along with 1D can be used either to access a single element or it can also be used to access the whole array. int ar[5], *ip; ar[0] ar[1] ar[2] ar[3] ar[4] ip=6; int ar[5], *ip; //wrong in C ip=&ar[3];//&--address of &-takes address of an object Ip &ar[3] *-the thing pointed to by the pointer &1.5-error(constants don t have addresses) *p=0;//writes zero into thing pointed to by p *p+=1;//adds one to where p points ar[0] ar[1] ar[2] ar[3] ar[4] Program to display 1D array elements Using pointers Without pointers Int *ptr,i; Int I; Int num[]=10,20,30,40,50,60; Int num[]=10,20,30,40,50,60; i=0; i=0; Ptr=&a[0]; While(i<=5) While(i<=5) Printf( Address=%u,&num[i]); Printf( Address=%u,ptr); Printf( element=%d,num[i]); Printf( element=%d,*ptr); i++; i++; Ptr++; Subject Notes by Hammad Lari 10
11 Program to display 2D array elements Using pointers Int *ptr,i,j; Int a[3][2]=100,200,300,400,500,600; Ptr=&a[0][0]; for(i=0;i<=2;i++) Printf( \n ); for(j=0;j<=1;j++) Printf( %d\t,*ptr); Ptr++; Array of Pointers Array of pointers refer to homogeneous collection of pointers. int *ptr[50]; int a[20],b[30],c[10]; Int *ptr[50]; Ptr[0]=&a[0]; Ptr[20]=&b[0]; Ptr[40]=&c[0]; Program Char *ptr[3]; Ptr[0]= hello ; Ptr[1]= how ; Ptr[2]= home ; Printf( %s%s%s,ptr[0],ptr[1],ptr[2]); Subject Notes by Hammad Lari 11
12 Array of Structures Struct employee Int number; Char sex; Int salary; ; Memory space for 3 objects employee data[3]=146, m,1000,200, f,5000,250, m,10000; Practice Problems 1. Wap to evaluate average of 5 numbers 2. Wap to find whether given prime number is palindrome or not. 3. Wap for addition of two matrix. 4. Wap for multiplication of two matrix. 5. Wap for transpose of a matrix 6. Wap to find highest and lowest element in an array 7. Wap to determine if matrix is symmetrical(a=a ). 8. Wap to combine two strings 9. Wap to compare two string 10. Wap to count number of vowels and digits in a given string. 11. Wap to check whether a string is palindrome or not. Subject Notes by Hammad Lari 12
13 Class Website Subject Notes by Hammad Lari 13
An array is a collection of similar elements that is all the elements in an array should have same data type. This means that an array can store
An array is a collection of similar elements that is all the elements in an array should have same data type. This means that an array can store either all integers, all floating point numbers, all characters,
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 informationMulti-Dimensional arrays
Multi-Dimensional arrays An array having more then one dimension is known as multi dimensional arrays. Two dimensional array is also an example of multi dimensional array. One can specify as many dimensions
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 informationChapter4: Data Structures. Data: It is a collection of raw facts that has implicit meaning.
Chapter4: s Data: It is a collection of raw facts that has implicit meaning. Data may be single valued like ID, or multi valued like address. Information: It is the processed data having explicit meaning.
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 informationDarshan Institute of Engineering & Technology for Diploma Studies Unit 5
1 What is structure? How to declare a Structure? Explain with Example Structure is a collection of logically related data items of different data types grouped together under a single name. Structure is
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 informationNCS 301 DATA STRUCTURE USING C
NCS 301 Data Structure Using C NCS 301 DATA STRUCTURE USING C Unit-1 Part-1 Intro to Data Structures Hammad Mashkoor Lari Assistant Professor Allenhouse Institute of Technolgy www.ncs301ds.wordpress.com
More informationArrays. Arrays are of 3 types One dimensional array Two dimensional array Multidimensional array
Arrays Array is a collection of similar data types sharing same name or Array is a collection of related data items. Array is a derived data type. Char, float, int etc are fundamental data types used in
More informationTypes of Data Structures
DATA STRUCTURES material prepared by: MUKESH BOHRA Follow me on FB : http://www.facebook.com/mukesh.sirji4u The logical or mathematical model of data is called a data structure. In other words, a data
More informationQuestions Bank. 14) State any four advantages of using flow-chart
Questions Bank Sub:PIC(22228) Course Code:-EJ-2I ----------------------------------------------------------------------------------------------- Chapter:-1 (Overview of C Programming)(10 Marks) 1) State
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 informationNCS 301 DATA STRUCTURE USING C
NCS 301 DATA STRUCTURE USING C Unit-1 Part-4 Linked Lists Hammad Mashkoor Lari Assistant Professor Allenhouse Institute of Technology www.ncs301ds.wordpress.com Introduction List refers to linear collection
More informationDC54 DATA STRUCTURES DEC 2014
Q.2 a. Write a function that computes x^y using Recursion. The property that x^y is simply a product of x and x^(y-1 ). For example, 5^4= 5 * 5^3. The recursive definition of x^y can be represented as
More informationClassification s of Data Structures
Linear Data Structures using Sequential organization Classification s of Data Structures Types of Data Structures Arrays Declaration of arrays type arrayname [ arraysize ]; Ex-double balance[10]; Arrays
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 informationData Structures. Chapter 04. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU
Data Structures Chapter 04 1 Linear Array A linear array is a list of finite number N of homogeneous data elements such that: The elements of the array are referenced respectively by an index set consisting
More informationIV Unit Second Part STRUCTURES
STRUCTURES IV Unit Second Part Structure is a very useful derived data type supported in c that allows grouping one or more variables of different data types with a single name. The general syntax of structure
More informationIn the previous lecture, we learned about how to find the complexity of algorithms and search algorithms on array.
Lecture 2 What we will learn 1. Definition of Arrays 2. Representation of Arrays in memory 3. Row-major Order and Column-major Order In the previous lecture, we learned about how to find the complexity
More informationProgramming 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 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 informationPointers and Arrays 1
Pointers and Arrays 1 Pointers and Arrays When an array is declared, The compiler allocates sufficient amount of storage to contain all the elements of the array in contiguous memory locations The base
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 informationNCS 301 DATA STRUCTURE USING C
NCS 301 DATA STRUCTURE USING C Unit-1 Part-2 Recursion Hammad Mashkoor Lari Assistant Professor Allenhouse Institute of Technology www.ncs301ds.wordpress.com Introduction Recursion is defined as defining
More informationTopics so far. Review. scanf/fscanf. How data is read 1/20/2011. All code handin sare at /afs/andrew/course/15/123/handin
15-123 Effective Programming in C and Unix Announcements SL2 is due Thursday 1/20 midnight Complete the Academic Honesty Form in class All code downloads are from /afs/andrew/course/15/123/download All
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)
Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate
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 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 - V STRUCTURES AND UNIONS
UNIT - V STRUCTURES AND UNIONS STRUCTURE DEFINITION A structure definition creates a format that may be used to declare structure variables. Let us use an example to illustrate the process of structure
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER
Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate
More informationArrays and Pointers. CSE 2031 Fall November 11, 2013
Arrays and Pointers CSE 2031 Fall 2013 November 11, 2013 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 Arrays: Example
More informationPointers. Memory. void foo() { }//return
Pointers Pointers Every location in memory has a unique number assigned to it called it s address A pointer is a variable that holds a memory address A pointer can be used to store an object or variable
More informationData and File Structures Laboratory
Review of C Arrays, Pointers, Dynamic Memory Allocation, Structures Assistant Professor Machine Intelligence Unit Indian Statistical Institute, Kolkata July, 2018 1 Arrays 2 Pointers 3 Dynamic Memory Allocation
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 informationThe time and space are the two measure for efficiency of an algorithm.
There are basically six operations: 5. Sorting: Arranging the elements of list in an order (either ascending or descending). 6. Merging: combining the two list into one list. Algorithm: The time and space
More informationExample: Structure, Union. Syntax. of Structure: struct book { char title[100]; char author[50] ]; float price; }; void main( )
Computer Programming and Utilization ( CPU) 110003 Structure, Union 1 What is structure? How to declare a Structure? Explain with Example Structure is a collection of logically related data items of different
More informationDATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305
Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n
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 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 informationArrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014.
Arrays Arrays and Pointers l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. EECS 2031 Fall 2014 November 11, 2013 1 2 Arrays: Example
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 informationUnit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array?
1 What is an array? Explain with Example. What are the advantages of using an array? An array is a fixed-size sequenced collection of elements of the same data type. An array is derived data type. The
More informationStructure, Union. Ashishprajapati29.wordpress.com. 1 What is structure? How to declare a Structure? Explain with Example
Structure, Union 1 What is structure? How to declare a Structure? Explain with Example Structure s a collection of logically related data items of different data types grouped together under a single name.
More informationTo store the total marks of 100 students an array will be declared as follows,
Chapter 4 ARRAYS LEARNING OBJECTIVES After going through this chapter the reader will be able to declare and use one-dimensional and two-dimensional arrays initialize arrays use subscripts to access individual
More informationSTRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY
STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY Objectives Declaration of 1-D and 2-D Arrays Initialization of arrays Inputting array elements Accessing array elements Manipulation
More informationUnit 7. Functions. Need of User Defined Functions
Unit 7 Functions Functions are the building blocks where every program activity occurs. They are self contained program segments that carry out some specific, well defined task. Every C program must have
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 informationLong Questions. 7. How does union help in storing the values? How it differs from structure?
Long Questions April/May - 2010 Marks 1. Explain arithmetic operators and their precedence in C. 2. Explain the term structured programming with help of example 3. Write a program to read 10 numbers and
More informationMultidimension array, array of strings
1 Multidimension array, array of strings char messages[3][7] ={ Hello, Hi, There ; Array of strings 0 1 2 0 1 2 3 4 5 6 H e l l o \0 H i \0 T h e r e \0 Each row (e.g., message[0]) is a char array (string)
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 informationPointers and Arrays A QUICK PREVIEW OF FOR CHAPTERS 10 AND 11 CMPE13. Cyrus Bazeghi
Pointers and Arrays A QUICK PREVIEW OF FOR CHAPTERS 10 AND 11 Cyrus Bazeghi POINTERS AND ARRAYS We have briefly seen these before, here are the details Pointer Array Address of a variable in memory Allows
More informationDarshan Institute of Engineering & Technology for Diploma studies Unit 4
Pointer A pointer is a variable that contains address or location of another variable. Pointer is a derived data type in C. Pointers contain memory address as their values, so they can also be used to
More informationTOPICS TO COVER:-- Array declaration and use.
ARRAYS in JAVA TOPICS TO COVER:-- Array declaration and use. One-Dimensional Arrays. Passing arrays and array elements as parameters Arrays of objects Searching an array Sorting elements in an array ARRAYS
More informationUNIT III ARRAYS AND STRINGS
UNIT III ARRAYS AND STRINGS Arrays Initialization Declaration One dimensional and Two dimensional arrays. String- String operations String Arrays. Simple programs- sorting- searching matrix operations.
More information3.3 Structures. Department of CSE
3.3 Structures 1 Department of CSE Objectives To give an introduction to Structures To clearly distinguish between Structures from Arrays To explain the scenarios which require Structures To illustrate
More informationSubject: Fundamental of Computer Programming 2068
Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find
More informationa) (5 points) What is the output of the following code sequence? int *ptr = 0x1050; printf ("%x\n", ptr--); printf ("%x\n", ptr);
Problem 1: Short Answers (25 points) a) (5 points) What is the output of the following code sequence? int *ptr = 0x1050; printf ("%x\n", ptr--); printf ("%x\n", ptr); b) (5 points) What are the three basic
More informationMaltepe University Computer Engineering Department. BİL 133 Algoritma ve Programlama. Chapter 8: Arrays and pointers
Maltepe University Computer Engineering Department BİL 133 Algoritma ve Programlama Chapter 8: Arrays and pointers Basics int * ptr1, * ptr2; int a[10]; ptr1 = &a[2]; ptr2 = a; // equivalent to ptr2 =
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 informationLab 3. Pointers Programming Lab (Using C) XU Silei
Lab 3. Pointers Programming Lab (Using C) XU Silei slxu@cse.cuhk.edu.hk Outline What is Pointer Memory Address & Pointers How to use Pointers Pointers Assignments Call-by-Value & Call-by-Address Functions
More informationPractice problems Set 2
Practice problems Set 2 1) Write a program to obtain transpose of a 4 x 4 matrix. The transpose of matrix is obtained by exchanging the elements of each row with the elements of the corresponding column.
More informationPDS Class Test 2. Room Sections No of students
PDS Class Test 2 Date: October 27, 2016 Time: 7pm to 8pm Marks: 20 (Weightage 50%) Room Sections No of students V1 Section 8 (All) Section 9 (AE,AG,BT,CE, CH,CS,CY,EC,EE,EX) V2 Section 9 (Rest, if not
More informationMore about BOOLEAN issues
More about BOOLEAN issues Every boolean test is an implicit comparison against zero (0). However, zero is not a simple concept. It represents: the integer zero for all integral types the floating point
More informationArrays in C. Data and File Structures Laboratory. DFS Lab (ISI) Arrays in C 1 / 1
Arrays in C Data and File Structures Laboratory http://wwwisicalacin/~dfslab/2017/indexhtml DFS Lab (ISI) Arrays in C 1 / 1 What is an array? A A[0] A[1] A[2] A[n 1] Syntax Sequence of n contiguous memory
More informationTwo Dimensional Arrays
2-d Arrays 1 Two Dimensional Arrays We have seen that an array variable can store a list of values Many applications require us to store a table of values Student 1 Student 2 Student 3 Student 4 Subject
More informationAssist. Prof. Dr. Caner ÖZCAN
Assist. Prof. Dr. Caner ÖZCAN Memory Structure When a variable defined it is stored somewhere in memory. Memory can be thought as block consist of cells. When a variable defined, required number of cell
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 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 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 informationOne Dimension Arrays 1
One Dimension Arrays 1 Array n Many applications require multiple data items that have common characteristics In mathematics, we often express such groups of data items in indexed form: n x 1, x 2, x 3,,
More informationITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University
ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 10: Arrays Readings: Chapter 9 Introduction Group of same type of variables that have same
More informationLow-Level C Programming. Memory map Pointers Arrays Structures
Low-Level C Programming Memory map Pointers Arrays Structures Memory Map 0x7FFF_FFFF Binaries load at 0x20000 by default Stack start set by binary when started Stack grows downwards You will need one stack
More informationUnit 3 Decision making, Looping and Arrays
Unit 3 Decision making, Looping and Arrays Decision Making During programming, we have a number of situations where we may have to change the order of execution of statements based on certain conditions.
More informationCS2351 Data Structures. Lecture 7: A Brief Review of Pointers in C
CS2351 Data Structures Lecture 7: A Brief Review of Pointers in C 1 About this lecture Pointer is a useful object that allows us to access different places in our memory We will review the basic use of
More informationPES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo
PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo 1. (a)what is an algorithm? Draw a flowchart to print N terms of Fibonacci
More informationArrays. CSE / ENGR 142 Programming I. Chapter 8. Another Motivation - Averaging Grades. Motivation: Sorting. Data Structures.
CSE / ENGR 142 Programming I Arrays Chapter 8 8.1 Declaration and Referencing 8.2 Subscripts 8.3 Loop through arrays 8.4 & 8.5 Arrays arguments and parameters 8.6 Example 8.7 Multi-Dimensional Arrays 1998
More informationArray. Arijit Mondal. Dept. of Computer Science & Engineering Indian Institute of Technology Patna IIT Patna 1
IIT Patna 1 Array Arijit Mondal Dept. of Computer Science & Engineering Indian Institute of Technology Patna arijit@iitp.ac.in Array IIT Patna 2 Many applications require multiple data items that have
More informationQuestion Bank (SPA SEM II)
Question Bank (SPA SEM II) 1. Storage classes in C (Refer notes Page No 52) 2. Difference between function declaration and function definition (This question is solved in the note book). But solution is
More informationLanguage comparison. C has pointers. Java has references. C++ has pointers and references
Pointers CSE 2451 Language comparison C has pointers Java has references C++ has pointers and references Pointers Values of variables are stored in memory, at a particular location A location is identified
More informationCS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/
CS61C Machine Structures Lecture 4 C Pointers and Arrays 1/25/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L04 C Pointers (1) Common C Error There is a difference
More information'C' Programming Language
F.Y. Diploma : Sem. II [DE/EJ/ET/EN/EX] 'C' Programming Language Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1(a) Define pointer. Write syntax
More informationIntroduction to Arrays
Introduction to Arrays One Dimensional Array. Two Dimensional Array. Inserting Elements in Array. Reading Elements from an Array. Searching in Array. Sorting of an Array. Merging of 2 Arrays. What is an
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 informationA. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS
Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization
More informationPointers. Part VI. 1) Introduction. 2) Declaring Pointer Variables. 3) Using Pointers. 4) Pointer Arithmetic. 5) Pointers and Arrays
EE105: Software Engineering II Part 6 Pointers page 1 of 19 Part VI Pointers 1) Introduction 2) Declaring Pointer Variables 3) Using Pointers 4) Pointer Arithmetic 5) Pointers and Arrays 6) Pointers and
More informationEM108 Software Development for Engineers
EE108 Section 6 Pointers page 1 of 20 EM108 Software Development for Engineers Section 6 - Pointers 1) Introduction 2) Declaring Pointer Variables 3) Using Pointers 4) Pointer Arithmetic 5) Pointers and
More informationUNDERSTANDING THE COMPUTER S MEMORY
POINTERS UNDERSTANDING THE COMPUTER S MEMORY Every computer has a primary memory. All our data and programs need to be placed in the primary memory for execution. The primary memory or RAM (Random Access
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 informationM3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE
M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be
More informationData Structures Through C. Student Workbook
Data Structures Through C Student Workbook Contents Lecture 1: C Revision I 01 Importance of data structures Data types in C Instructions and its types The decision control instruction Working of logical
More informationPointers, Arrays and C-Strings
Pointers, Arrays and C-Strings Data Processing Course, I. Hrivnacova, IPN Orsay Variable in Memory Pointers Nullptr Pointers vs References C-Arrays C-Strings Problems with C-Arrays, C-Strings 1 Variables
More informationAE52/AC52/AT52 C & Data Structures JUNE 2014
Q.2 a. Write a program to add two numbers using a temporary variable. #include #include int main () int num1, num2; clrscr (); printf( \n Enter the first number : ); scanf ( %d, &num1);
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 informationComputer Programming
Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering Session: Introduction to Pointers Part 1 Dr. Deepak B. Phatak & Dr. Supratik Chakraborty,
More informationIMPORTANT QUESTIONS IN C FOR THE INTERVIEW
IMPORTANT QUESTIONS IN C FOR THE INTERVIEW 1. What is a header file? Header file is a simple text file which contains prototypes of all in-built functions, predefined variables and symbolic constants.
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 informationArrays and Pointers (part 1)
Arrays and Pointers (part 1) CSE 2031 Fall 2012 Arrays Grouping of data of the same type. Loops commonly used for manipulation. Programmers set array sizes explicitly. Arrays: Example Syntax type name[size];
More informationLab #10 Multi-dimensional Arrays
Multi-dimensional Arrays Sheet s Owner Student ID Name Signature Group partner 1. Two-Dimensional Arrays Arrays that we have seen and used so far are one dimensional arrays, where each element is indexed
More information