Skip to main content

Posts

Showing posts from July, 2019

Operation on Array

Basic Operations : Following are the basic operations supported by an array. Traverse − print all the array elements one by one. Insertion − Adds an element at the given index. Deletion − Deletes an element at the given index. Search − Searches an element using the given index or by the value. Update − Updates an element at the given index. Traversing Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms. Traverse − print all the array elements one by one.or process the each element one by one . Let A be a collection of data elements stored in the memory of the computer. Suppose we want to print the content of each element of A or suppose we want to count the number of elements of A with given property. This can be accomplished by traversing A, that is, by accessing and processing (frequently called visiting) each element of An exactly once...

Memory Representation of Array

Already discussed that whenever an array is declared in the program, contiguous memory to it elements are allocated. Initial address of the array – address of the first element of the array is called base address of the array. Each element will occupy the memory space required to accommodate the values for its type, i.e.; depending on elements datatype, 1, 4 or 8 bytes of memory is allocated for each elements. Next successive memory address is allocated to the next element in the array. This process of allocating memory goes on till the number of element in the array gets over. One Dimensional Array : Below diagram shows how memory is allocated to an integer array of N elements. Its base address – address of its first element is 10000. Since it is an integer array, each of its element will occupy 4 bytes of space. Hence first element occupies memory from 10000 to 10003. Second element of the array occupies immediate next memory address in the memory, i.e.; 10004 which requi...

Array

An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. This makes it easier to calculate the position of each element by simply adding an offset to a base value, i.e., the memory location of the first element of the array (generally denoted by the name of the array). The array is a fixed-size sequenced collection of variables belonging to the same data types. The array has adjacent memory locations to store values. Since the array provides a convenient structure for representing data, it falls under the category of the data structures in C. The syntax for declaring array are: data_type array_name [array_size]; The following are two terminology are used in Array data structure: Element : Every item stored in an array is termed as an element Index : each memory location of an element in an array is denoted by a numerical index which is used for identifying the element. Why you need ? When a ...