Cooler_

void pointer example

Oct 30th, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. // example void pointer by Cooler_
  2. #include <stdio.h>
  3.  
  4. void foo(void *point,int size)
  5. {
  6. // int == 4 bytes
  7.  if(size==sizeof(int))
  8.   printf("int : %d , bytes: %d\n",*(int *)point,sizeof(point));
  9.  
  10. // double == 8 bytes
  11.  if(size==sizeof(double))
  12.   printf("double : %f , bytes: %d\n",*(double *)point,sizeof(double));
  13. }
  14.  
  15. int main()
  16. {
  17.  int a=64;
  18.  double b=3.14;
  19.  void *o=&b,*z=&a;
  20.  
  21.  printf("bytes of void : %d\n",sizeof(void));
  22.  foo(z,sizeof(int));
  23.  foo(o,sizeof(double));
  24.  
  25.  return 0;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment