0
#import <Foundation/Foundation.h>

/* function to generate and return random numbers. */
int * getRandom( )
{
   static int  r[10];
   int i;

   /* set the seed */
   srand( (unsigned)time( NULL ) );
   for ( i = 0; i < 10; ++i)
   {
      r[i] = rand();
      NSLog(@"%d\n", r[i] );
   }
  NSLog(@"checking for r value: %d\n", r );
   return r;
}

/* main function to call above defined function */
int main ()
{
   /* a pointer to an int */
   int *p;
   int i;

   p = getRandom();
   for ( i = 0; i < 10; i++ )
   {
       NSLog(@"*(p + [%d]) : %d\n", i, *(p + i) );
   }`enter code here`

   return 0;
}

Please I need an explanation on something, am new to objective-c, on running the above code, ("checking for r value: 6296000") became the output of "NSLog(@"checking for r value: %d\n", r )", r became 6296000, please whats the meaning of 6296000 that am getting for the value of r.

newacct
  • 119,665
  • 29
  • 163
  • 224

1 Answers1

0

You are printing the pointer r (first pointer in the array of ints).

To print the value of a position in the array use r[position].

6296000 is the base 10 version of the address of the pointer to the array r.

silassales
  • 36
  • 8