Monday, May 13, 2019

Define Array Syntax and Uses

                          Define Array and syntax and uses?

Define array

An array is a collection of data items, all of the same type, accessed using a common name. A one-dimensional array is like a list; A two dimensional array is like a table; The C language places no limits on the number of dimensions in an array, though specific implementations may.

A one-dimensional array is like a list; A two dimensional array is like a table; the C language places no limits on the number of dimensional in an array, though specific implementations may.

https://amzn.to/2LPMKiu
B07BZQHQ66
How to declare arrays?(syntax)
data_type array_name[array_size];

Using Arrays

  • Elements of an array are accessed by specifying the index (offset) of the desired element within square [ ] brackets after the array name.
  • Array subscripts must be of integer type. ( int, long int, char, etc).
https://amzn.to/2W0gvB8
B07C26VTMK
Very Important


Indices start at zero in C, and go to one less than the size of the array. for example, a five element array will have indices zero through four. This is because the index in C is actually an offset from the beginning of the array. ( The first element is at the beginning of the array, and hence has zero offset.)
  
For example,
float marks[15];

 Element of an Array and How to access them?

You can access elements of an array by indices.
suppose you declared an array mark as above. The first element is mark[0], second element is mark[1] and so on.

https://amzn.to/2JD2W3W

B07DN74N8B
Few Key notes:

  • arrays have 0 as the first index not 1. In this Example, mark[0]
  • If the size of an array is n, to access the last element, (n-1) index is used. In this example, mark[4]
  • Suppose the starting address of mark[0] is 2120d. Then, the next address, a[1] will be 2124d, address of a[2] will be 2128d and so on. It's because the size of a float is 4 bytes.
Important thing to remember when working with C arrays

You can use the array members from testArray[0] to testArray[9].
 If you try to access array elements outside of its bound, let's say testArray[12], the compiler may not show any error. However, this may cause unexpected output (undefined behavior). 

Important overview

Dimensional used when declaring arrays in C must be positive integral constants or constant expressions.
  • In C99, dimensions must still be positive integers, but variables can be used, so long as the variable has a positive value at the time the array is declared. ( space is allocated only once, at the time the array is declared. The array does NOT change sizes later if the variable used to declare it changes.
https://amzn.to/2WEKqfv
B01GUXR8VO

Amazing offer for amazon buy any products and 20% to 30% off below the link. click the and get off buy the product. So  amazing offer for amazon. Only for this link offer.
B016C2I696
B07MJJ34LF

No comments:

Post a Comment

PHP Tutorial

                                                                  PHP Tutorial The PHP Hypertext Preprocessor (PHP) is a programming la...