All pastes #483449 Raw Edit

Untitled

public text v1 · immutable
·published 2007-05-11 19:06 UTC
rendered paste body
// Given an array A and the address of element A[x], find the value of  x
#include <stdio.h>
#define TESTVALUE 5
int main(void)
{
  int x=TESTVALUE;
  int A[]={0,1,2,3,4,5,6,7,8,9};
  int one_element=sizeof(A[0]);
  printf("one_element=%d\n", one_element);
  int finding_x=( (unsigned long)(&A[x]) - (unsigned long)(&A[0]) )/
one_element ;
  printf("Address &A[x]=%p\n", &A[x] );
  printf("Address &A[0]=%p\n", &A[0] );
  printf("finding_x=%d\n", finding_x);
  return 0;
}