Page 112 - 6437
P. 112

/* set the seed */

                                srand( (unsigned)time( NULL ) );

                                for ( i = 0; i < 10; ++i)
                                {
                                   r[i] = rand();

                                   printf("%d\n", r[i] );

                                }


                                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++ )
                                {

                                    printf("*(p + [%d]) : %d\n", i, *(p + i) );
                                }


                                return 0;

                            }

                          When the above code is compiled together and executed, it produces the following result:




                 1523198053
                 1187214107

                 1108300978
                 430494959

                 1421301276
                 930971084

                                                                                                     115
   107   108   109   110   111   112   113   114   115   116   117