fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(void) {
  4.  
  5. int **p;
  6. int *arr,i;
  7. p= malloc(sizeof(int *)); // allocate memory for 1 int 8*
  8. p[0]=malloc(5*sizeof(int)); // allocate memory to int *
  9. for(i = 0; i < 5; i++){
  10. p[0][i] = i+1; // initialization
  11. }
  12. arr= malloc(5 * sizeof(int)); // allocate memory to arr
  13. memcpy(arr,&p[0][2],3*sizeof(int)); // copy last 3 elements to arr
  14.  
  15. for( i=0;i<3;i++){
  16. printf("%d",arr[i]); // print value in arr
  17. }
  18. free(p[0]);
  19. free(p);
  20. free(arr);
  21.  
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 2244KB
stdin
Standard input is empty
stdout
345