Skip to main content

Introduction To Array In C Language

Introduction To Array:
*Array Is A Type Of Data Structure Which Store Collection of Data Of
 Same Type.Which Can Be Integer Float Or Character.
*All arrays consist of contiguous memory locations.
*The lowest address corresponds to the first element and the highest
 address to the last element.

Declaration Of Array:-
It Consist up of 3 part :-
1.Data Type 
2.Array Name
3.Size Of Array
General Syntax:-                                                     
data_type Array_name[size_of_array];
For Example:-
 int marks[20];
in example datatype of array is int and name is marks and size is 20.
* It Is Called Single Dimensional Array
* the Array Size Must be Integer And it
  must be greater than zero.
Initialization Of Array:
*We initialize an array in C either one by one or using a single statement                
 as follows:
 For Example:-                                                                    
int marks[5]={95,96,97,98,99}; 
*The number of values between braces { } cannot be larger than the number of
 elements that we declare for the array between square brackets [ ].          
*All arrays have 0 as the index of their first element which is also called base
index and the last index of an array will be total size of the array minus 1.
Accessing Array Elements:-
We Use for loop from zero to less than array size.this is described in
below program:-
Example Program:-
#include <stdio.h>
int main ()
{
int a[8]; /* n is an array of 10 integers */
int i,j;
/* initialize elements of array n to 0 */
for (i=0; i<8; i++)
{
a[i] = i + 200; /* set element at location i to i+200 */                
}
 /* output each array element's value */
for (j=0; j<8; j++)
{
printf("Element[%d] = %d\n", j, a[j] );
}
return 0;
}
The Output Of Program Is:-
Element[0] = 200
Element[1] = 201
Element[2] = 202
Element[3] = 203
Element[4] = 204
Element[5] = 205
Element[6] = 206
Element[7] = 207
Types Of Array:-
1)One Dimensional Array
2)Two Dimensional Array
3)Multidimensional Array

This Will Describe In next Posts:-
                               
             -:PLEASE SHARE US:-
         -:THANKS A LOT:-

















Comments

Popular posts from this blog

Introductution To Structures In C Language

About Structure:- Arrays allow to define a type of variables that can hold several data items of the same kind. Similarly, structure is another user-defined data type available in C that allows to combine data items of different kinds. Let Us Take An Real Life Example: If We want to track the following attributes about each book: 1.Title (May Be String) 2.Author(May Be String) 3.Subject (May Be String) 4.Book ID (Integer Type) Than We Have to Define A Structure Variable That Can Take This Different Type Of Data-Types. Syntax For Defining A Structure:- struct [structure_Name] { member definition; member definition; ... member definition; } [one or more structure variables]; For Information of Student The Definition of structure Will Be: struct student_data {  char name[20];  int roll_Number;  int standered;  char father's_name[20]; } std1; //structure Vaiable   Accesing Structure Members:- The Members of structure variable accesed by Dot(.) Operator.. Let Us Take...

Use Of Pointers In C language

Use Of Pointer In C Language:- We Have already Discussed About Pointe rs In Previous Post. This is the most important and useful IN C programming . The Uses Of Pointers In C Language Is Given below:- 1.Array of pointers:- We Can Use Collection Of Pointer by using   An Array Of Pointers. 2.Pointer to pointer:- C allows you to have pointer on a pointer. 3.Passing pointers to functions:-  We Pass Pointer As  Arguments. Now We Will know About These Uses Of Pointers One By One:- 1.Array of pointers:- In This Method We Declare An array For Storing Pointers: declaration of an array of pointers to an integer:- int *ptr[MIN]; declaration of an array of pointers to an float:- flot *ptr[MIN]; declaration of an array of pointers to a CHAR:- char *ptr[]; Example Program:- THIS PROGRAM DEMONSTRATES ARRAY OF POINTER, WE SIMPLY PRINT ADDRESS AND VALUE OF POINTERS #include <stdio.h> const int MAX = 5; int main () { int *ptr; int var[] = {10, 100, 200,400,500}; int i; ptr=var; for (...