Advertisement
193030

Function that returns pointer

Jul 20th, 2021
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int *fun();
  5. int *fun2();
  6.  
  7. main()
  8. {
  9.     int *ptr;
  10.     ptr=fun();
  11.     printf("%d \n",*ptr);
  12.  
  13.     int *ptr2;
  14.     ptr2=fun2();
  15.     printf("%d \n",*ptr2);
  16.  
  17. }
  18. int *fun()
  19. {
  20.     int *point = malloc(sizeof *point); /* Mandatory. */
  21.     *point=12;
  22.     return point;
  23. }
  24.  
  25. int *fun2()
  26. {
  27.     int a = 22;
  28.     int *point = &a;
  29.     return point;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement