donneb

c lionm

Oct 24th, 2020
1,323
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /******************************************************************************
  2.  
  3.                             Online C Compiler.
  4.                 Code, Compile, Run and Debug C program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <stdio.h>
  10. long * move_to_function(long *arr, long nelements) {
  11.     long newArr[nelements];
  12.     newArr[0] = arr[nelements-1];
  13.    
  14.     int i;
  15.     for (i=0; i<nelements; i++) {
  16.         newArr[i + 1] = arr[i];
  17.     };
  18.    
  19.     long* arrb = &newArr;
  20.     return arrb;
  21. }
  22.  
  23. void printarr(long *arr, long nelements){
  24.     int i;
  25.     for (i=0; i<nelements; i++) {
  26.         printf("%ld ", arr[i]);
  27.     }
  28.     printf("\n");
  29. }
  30.  
  31. int main(void){
  32.  
  33.     long arr[5] = {10,11,12,13,14};
  34.     long nelements = 5;
  35.     long constval = 5;
  36.  
  37.     printarr(&arr, nelements);
  38.    
  39.     long *arrb;
  40.     arrb = move_to_function(&arr, nelements);
  41.    
  42.     printarr(arrb, nelements);
  43.     return 0;
  44. };
  45.  
  46.  
RAW Paste Data