Home > Back-end >  Pointer array value assignment
Pointer array value assignment

Time:01-16

Function pointer to create 10 X storage address, each address stored 100 4 bytes of data; The first address to store random data, the second address data is stored in the first address data on 1, the third address is stored in the second data plus 1

CodePudding user response:

 # include & lt; stdio.h> 
#include
#include
#include
//function function pointer to create 10 X storage address, each address stored 100 4 bytes of data; The first address to store random data, the second address data is stored in the first address data on 1, the third address is stored in the second data plus 1
Void fun () {
Int * * X;
int i;
Int j;

X=(int) * * malloc (10 * sizeof (int *));
for (i=0; i<10; I++) {
[I]=(int *) X malloc (100 * sizeof (int));
For (j=0; j<100; J++) {
If (I==0) X [I] [j]=rand ();
Else X [I] [j]=X [I - 1) [j] + 1;
}
}
for (i=0; i<10; I++) {
For (j=0; j<3; J++) {
Printf (" % d ", [I] X [j]);
}
Printf ("... \n");
}
for (i=0; i<10; I++) {
[I] free (X);
}
Free (X);
}
Int main () {
Srand (time (NULL));
Fun ();
return 0;
}
//30177 23612 6502...
//30178 23613 6503...
//30179 23614 6504...
//30180 23615 6505...
//30181 23616 6506...
//30182 23617 6507...
//30183 23618 6508...
//30184 23619 6509...
//30185 23620 6510...
//30186 23621 6511...
//
  • Related