India's Largest Free Online Education Platform

To find the address of 1-D array element

To find the address of 1-D array element

/*To find the location of targeted arr[i] entered by the user.
Address of array[j] =  Base Address +2 (Row or Column subscript-Lower limit of Row/column)    */

#include <stdio.h>  // header files
#include <stdlib.h>

int main()    // main function starts from here 
 long int arr[100],BA,i,j,lb,n,Lc,ch;  // variable declaration
 lb=0;  // variable initialization
 printf("\n Enter the size of integer type arary that you are going to enter\n");
 scanf("%d",&n);  // taking input as lenth of array 

 printf("\n Enter the elemets\n");

 printf(" Your entered array elemets are-\n"); // printing the array elements
 printf("\t %d",arr[i]);

 printf(" \n Choose an array element to find it's address\n");
 scanf("%d",&ch);  // taking input as a target element

 for(i=0;i<n;i++)   // loop 
   if(arr[i]==ch)   // checking equality


 printf(" \n Base address of this array by program itself calculation  is:%d\n",BA);

 Lc=(BA+(2*(j-lb)));  // formula for 1-D array address calculation
 printf("\nLocation of array element %d is :",ch);

return 0;
}  // end of main function

RESULT: Output

To find the address of 1-D array element
To find the address of 1-D array element

The above code can’t be directly copy-pasted. You must have to type with your own hand. This is made for your better future. 

Are you made for copy paste?

Absolutely “NO”

Then, try hard to understand this code and type with your own.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!