অনুরূপ অনেক Data একসাথে স্টোর করতে array এর ব্যবহার

Submitted by tushar pramanick on Mon, 01/02/2012 - 15:52

Storing Similar Data Items

In last Chapter you learned about pointers and the concept of indirection. In this lesson you'll learn about arrays, which are collections of similar data items and are closely related to pointers. The main topics covered in this lesson are

    Single-dimension arrays
    Indexing arrays
    Pointers and arrays
    Character arrays
    Multidimensional arrays
    Unsized arrays



Summary

In this lesson you've learned the following:

  •     An array is a collection of variables that are of the same data type.
  •     In C, the index to an array starts at 0.
  •     You can initialize each individual element of an array after the declaration of the array, or you can place all initial values into a data block surrounded by { and } during the declaration of an array.
  •     The memory storage taken by an array is determined by the product of the size of the data type and the dimensions of the array.
  •     A pointer is said to refer to an array when the address of the first element in the array is assigned to the pointer. The address of the first element in an array is also called the start address of the array.
  •     To assign the start address of an array to a pointer, you can either put the combination of the address-of operator (&) and the first element name of the array, or simply use the array name, on the right side of an assignment operator (=).
  •     A character array is considered a character string in C if the last element in the array contains a null character (\0).
  •     The null character (\0) marks the end of a string. C functions, such as printf(), will stop processing the string when the null character is encountered.
  •     C supports multidimensional arrays, too. A pair of brackets (the array subscript operator—[ and ]) indicates a dimension.
  •     The compiler can automatically calculate the memory space needed by an unsized array.

 

 

Related Items

The #define and #undef Directives

The #define and #undef Directives

The #define directive is the most common preprocessor directive, which tells the preprocessor to replace every occurrence of a particular character string (that is, a macro name) with a specified value (that is, a macro body).

The C Preprocessor Versus the Compiler

The C Preprocessor Versus the Compiler

One important thing you need to remember is that the C preprocessor is not part of the C compiler.

What Is the C Preprocessor?

If there is a constant appearing in several places in your program, it's a good idea to associate a symbolic name to the constant, and then use the symbolic name to replace the constant throughout the program. There are two advantages to doing so. First, your program will be more readable.

Exercises : Answer the following Question

To help solidify your understanding of this hour's lesson, you are encouraged to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson.

Question and Answer

    Q Why is random access to a disk file necessary?