Advertisement
rafikamal

Dynamic Memory Allocation

Jan 31st, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void swap(int *a, int *b);
  5.  
  6. int main()
  7. {
  8.     int *x, n, i;
  9.    
  10.     printf("How many numbers?\n");
  11.     scanf("%d", &n);
  12.     x = (int *)malloc(n*sizeof(int));
  13.    
  14.     for(i = 0; i < n; i++)
  15.         scanf("%d", &x[i]);
  16.        
  17.     free(x);
  18.    
  19.     return 0;
  20. }
  21.  
  22. void swap(int *a, int *b)
  23. {
  24.     int temp = *a;
  25.     *a = *b;
  26.     *b = temp;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement