Computer Languages

Read Complete Research Material

COMPUTER LANGUAGES

Computer Languages - Unleashed

Computer Languages - Unleashed

Matrices and Array in C and Java

The word 'Array' bears the same concept in both C as well as in Java, but the mode of execution is different for both languages. Let us consider the concept of arrays and matrices in C language first.

C-language

Basically, an array is a container object which has the ability to hold a fixed number of values having the same type and a distinct address.

For understanding the need for arrays in C-language, consider the following example;

int marks [8];

Here, 'int' represents the type of variable which is an integer and 'marks' represents the variable's name and the square bracket are used to specify the dimensions of the array. What happens in the memory? Whenever above array is declared, 12 bytes of the memory get reserved (2 bytes per integer). As the array is not initialized, all the eight values will be garbage in nature and will be assigned to the memory location. Declaring a 'static' variable will make the locations have zero stored. The following diagram shows the distribution of garbage values in address locations 65508, 65510 and so on.

. Figure 1: Memory mapping of an array (Kanetkar Y., 2007).

The two dimensional array is simply called matrix. Consider the following example to get a better understanding of declaring a matrix and the memory pattern that it bears.

int stud[4][2] = {

{ 1234, 56 },

{ 1212, 33 },

{ 1434, 80 },

{ 1312, 78 }

}

The first column [4] indicates the rows while the later columns. However, the memory map has two components; one is the row while the other one is column. The figure below shows a basic interpretation of arrangement while the next one represents the memory locations (Kanetkar Y., 2007, pp. 270,275-276, 289-292).

.

Figure 2: Basic Matrix Interpretation (Kanetkar Y., 2007).

Figure 3: Memory mapping of a Matrix in C (Kanetkar Y., 2007).

Java

The concept of the array and matrix is similar to the one in C language. Although, the declaration and initialization are different from that of C language. An array can be declared as;

// declares an array of integers

int anArray;

Take the example for initializing the following array.

int anArray = { 100, 200, 300,

400, 500, 600, 700, 800, 900, 1000

};

The array will have the following memory location

Figure 4: Memory mapping of an Array in Java (Docs.oracle.com, 1995).

For the matrix consider the following example;

class MultiDimArrayDemo {

public static ...
Related Ads
  • Computer Program
    www.researchomatic.com...

    Free research that covers introduction a is develope ...

  • E-Portfolio
    www.researchomatic.com...

    Java is considered to be the first programming langu ...

  • Computers As A Career
    www.researchomatic.com...

    There are over one thousand computer languages ...

  • Programming Languages
    www.researchomatic.com...

    During the 60s, while computers were still in ...

  • Programming Language~
    www.researchomatic.com...

    These codes are different from high level languag ...