Skip to main content

Interoduction Array

Arrays

In computer programming, an array is a data structure that stores a fixed-size sequence of elements of the same type. It is used to organize and manipulate collections of data effectively.

Arrays can be one-dimensional, two-dimensional (matrices), or multidimensional. A one-dimensional array uses a single index. A two-dimensional array uses two indices—one for rows and one for columns.

Arrays are used for storing numbers, characters, or objects, iterating through data, searching, sorting, and modifying values. They provide fast and direct access using index numbers.

In short summary:

  • Array is a collection of similar data types grouped under one name.
  • It is also called a vector.
  • All elements are accessed using index values.
  • Supported by almost all programming languages.

Example:

int A[5];   // Declaration
A[2] = 15; // Access

01234
    15    

Different ways of declaring and initializing arrays:

int A[5];
01234
? ? ? ? ?

Garbage values

int A[5] = {2,4,6,8,10};
01234
2 4 6 8 10

int A[5] = {2,4};
01234
2 4 0 0 0

int A[5] = {0};
01234
0 0 0 0 0

int A[] = {2,4,6,8,10};
01234
2 4 6 8 10

Traversing an array:

int A[5] = {2,4,6,8,10};
for (i = 0; i < 5; i++) {
     printf("%d", A[i]);
}

• Array elements can also be accessed using pointer notation.

Example:
int A[5] = {2,4,6,8,10};
for (i = 0; i < 5; i++) {
     printf("%d", A[i]);
     printf("%d", A[2]);
     printf("%d", 2[A]);
     printf("%d", *(A + 2));
}

Popular posts from this blog

Java

Codes With Java — Basics Codes With Java Java tutorials & fundamentals About Contact Privacy Basic Fundamentals Java source file structure Import Statement Static Import Packages Data Type Variables Final Variable Declaration and Access Modifier Inner classes applicable modifiers Static Modifier Synchronized Native Transient Volatile Interface Introduction Interface Declaration and Implementation Interface methods and variables Naming Conflicts Interface Marker interface and Ad...

Short Circuite Operators part 4

                                                             Short Circuit Operators In  Java logical operators , if the evaluation of a logical expression exits in between before complete evaluation, then it is known as  Short-circuit . A short circuit happens because the result is clear even before the complete evaluation of the expression, and the result is returned. Short circuit evaluation avoids unnecessary work and leads to efficient processing. 1-: AND(&&) 2-:OR(||) these are exactly same as bitwise operators (&,|) except the following differences. Single Short Circuit Operator(&,|) Both arguments Should be evaluated always. relatively performance is low. Applicable for both boolean and Integral types. Double Short Circuit Operator(...

Operators & Assignment part 3

                                                                                       Operators & Assignment 1-:instanceof Operators 2-:Bitwise Operators                                                                        instanceof Operators we can use instanceof operator to check whether the given object is of a particular type are not. Example-: /* list is a collection of objects. List l=new List(); l.add(Customer); l.add(Student); l.add(Test); Object o=l.get(...