Showing posts with label Programming Fundamental. Show all posts
Showing posts with label Programming Fundamental. Show all posts

Sunday, March 8, 2015

BASIC CONCEPTS OF AN ARRAYS

     
EXAMPLE WITH C

This Article Introduce to below this Topic’s
A.      Introduction of Array with example
B.      Types of Array with example
C.      Initialization of Arrays
D.      Example with C Program

A.   Introduction of Arrays
An array can be defined as an area in memory. This can be referred to by a common name. Arrays are used to set of group like object.
         Each element of the array can be referred to by the array name and a subscript or index
Syntax:-
Datatype arrayname [n];

B.   Types of Array with example
There are two types of array
*      One –dimensional  / Single –dimensional array
*      Two-dimensional  / Multi-dimensional arrays
One –dimensional / Single –dimensional array
  An array is declared as containing a certain datatype and internally they are stored as a contiguous set of these data types.
Int numbers [10];
This defines an integer array called numbers. The array can hold 10 integer values, which will be stored the elements numbers [0] to numbers [9].
Float fnums [10];
This defines a float array called fnums. The array can hold 10 float values, which will be stored the elements fnums [0] to fnums [9].
Char name [10];
This defines a character array called name .the array can hold 10 characters values, which will be stored the elements name [0] to name [9].
Initialization of One-dimensional/Single-dimensional Array
An array can be initialized, when declared by specifying the vales of some or all of its elements .this initialization at a time of declaration is possible only outside a function unless it is declared static.
             Initialization can also be done inside the function after the array has been declared by accepting the values.
Char name [7] = {‘K’,’r’,’i’,’s’,’h’,’n’,’a’, \0’};
Char name [7] = {‘Krishna’};
      In that first case individual elements have been moved into the array and hence it is essential that the name terminator be specified explicitly.
        In that second case, the name terminator gets attached automatically because a name has been assigned.
Int ages [] = {19, 23, 45.27, 28, 29};
                In that case integer and float individual value have to be moved into the elements. In the proceeding declaration the dimension has not been specified for reason of flexibility, the compiler will automatically calculate the dimension based on the initialization.
Two-dimensional / Multi-dimensional arrays
               A two-dimensional array is in essence an array of one –dimensional array.it is also known as “two-d array”.
Syntax:-
 Datatype arrayname[x] [y];
              Each dimension of the two –d array has been placed in a separate set of brackets. Two-d arrays are stored in a row –column matrix, in which the first index indicates the row and second indicates the column.to access a specific element, either the indices or subscripts have to be specified.

Initializing Multi-dimensional/ Two-dimensional arrays
The rules for initialization of two-d array are the same as a one –dimensional array. Initialization at the time of declaration must be done outside the function or must be declared static within the function.
Ex: -      int squares [10] [2] =
{
{1, 1},
{1, 2},
{2, 3},
{3, 4},
{4, 5},
{5, 6},
{6, 7},
{7, 8},
{8, 9},
{9, 0}
};
Ex: -           Int sales [3] [4] = {
                  {143, 234},
                 {253, 567,546},
                 {786, 657, 890, 543}
                     };
Only the two elements of the first row, three in the second row, and four in the third row are initialized.                                                    
                                         As usual, the array can also be initialized inside the function by accepting the values.
Character arrays initialized in two-dimensional arrays
Char name [7] [3] = {
{‘Krishna’},
{‘Radikaa’},
{‘Govinda’}
};




 I hope this Article Helpful for you..:)-

Saturday, March 7, 2015

Data types in C++

Data types in C++:

                The variable type specifies the type of data that can be stored in it. Each variable  is declared by its  type.
C++ has five basic data type. These are
int                          Integer
float                       Floating point
double                   Double precision
char                       Characters
bool                       Boolean

First five data type are also available in C language. The bool is data type a new addition in C++.

The int data type:
                                  This data type is used to declare integer data type variable. An integer is whole number .the storage capacity of int type variable can be changed by applying the   integer qualifiers. There are three qualifiers that can be applied to int data type variables. These are
Short int(storage capacity  is 2 byte)
Long int (storage capacity is 4 byte)
Unsigned int(storage capacity is 2 byte and store only positive whole number)

Float data type:
                                       Float represents real or floating type data. The real data type is represented in decimal or exponential notation it may be signed or unsigned and its storage capacity is 4 byte.

Char data type:
                                      The char stands for character. It is used to declare character type variable. In character type variable, alphabetic characters, numeric digits and special charters can be stored.

Bool data type:
                         The word bool stand for Boolean. It is used to declare logical type variables. In logical type variable only two values true or false can be stored. True is equivalent to 1 and false to 0.



Data Types Characteristics