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

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 (...

Calling Method Of Function In C Language

Calling Method In C Language:- As We Already See That Any Function has Some Arguments Or void If We Use Variable As Argument Then It Is Called FORMAL PARAMETERS. *Formal parameters behave like other local variables inside the function  and are created upon entry into the function and destroyed upon exit. In C Language there are two ways in which arguments can be passed to a function:- 1)Call by value:-      (using value) 2)Call by reference:-  (using pointer) Now We Will See One By One These Arguments By Taking Suitable Example: 1)Call by value:-  *In This Method actual value copies to formal parameter: *Due To That changes made to the parameter inside the function  have no effect on the argument. This will cleared by following example:- Example Program:- //in this program we swap two variable using third variable: #include <stdio.h> /* function declaration */ void swapping(int a, int b); int main () { /* local variable definition */ int x =...