Advertisement
Broatlas

Untitled

Feb 4th, 2016
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. /* function to generate and return random numbers */
  4. int * getRandom( ) {
  5.  
  6.    static int  r[10];
  7.    int i;
  8.  
  9.    /* set the seed */
  10.    srand( (unsigned)time( NULL ) );
  11.  
  12.    for ( i = 0; i < 10; ++i) {
  13.       r[i] = rand();
  14.       printf( "r[%d] = %d\n", i, r[i]);
  15.    }
  16.  
  17.    return r;
  18. }
  19.  
  20. /* main function to call above defined function */
  21. int main () {
  22.  
  23.    /* a pointer to an int */
  24.    int *p;
  25.    int i;
  26.  
  27.    p = getRandom();
  28.  
  29.    for ( i = 0; i < 10; i++ ) {
  30.       printf( "*(p + %d) : %d\n", i, *(p + i));
  31.    }
  32.  
  33.    return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement