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

Basic Syntax Of "C" Language

1).Tokens In C Language:- A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol. For example, the following C statement consists of five tokens:        printf("Hello, World! \n"); 1.printf 2.( 3."Hello, World! \n" 4.) 5.;(semicolon) Let Us Describe about these Tokens One By One:- A.) Semicolons:- the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity. For Example: printf("Helo"); getch(); Given Above Is Example Of Termination Of Two Statements. B.)Comments:- Comments are like helping text in your C program and they are ignored by the compiler. They start with /* and terminate with the characters */ as shown below: /*This Is My First Program*/        OR We can use double slash(//) for comment one line as:- //this is My First Program C.) Identifiers:- A C identifier is a name used ...

Pointer In C Language

          Introduction To Pointer: About Pointer:- *POINTER is a variable whose value is the address of another variable *Every variable is a memory location and every memory location  has its address defined which can be accessed using ampersand(&)  operator,which denotes an address in memory *Dynamic memory allocation,cannot be performed without using pointers. Let's start learning them in simple and easy steps. pointer variable declaration:- data_type *variable_name; *The asterisk ( * ) used to declare a pointer is the same asterisk used for   multiplication. some of the valid pointer declarations:- int *in;             //pointer to an intege r  double *db;  // pointer to a double  float *fl;         //  pointer to a float  char *chr    //pointer to a character   *The only difference between pointers of different data types is the data type of the va...