打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
【例题】指针
  1. '' 变量指针:
  2. ''
  3. dim as integer i = 5
  4. dim as integer ptr p
  5.  
  6. = @i
  7. print i, *p
  8.  
  9. ''
  10. ''程序指针:
  11. ''
  12. sub sayhi( )
  13. print "hi"
  14. end sub
  15.  
  16. sayhi( )
  17.  
  18. dim psayhi as sub( ) = @sayhi
  19. psayhi( )
  20.  
  21.  
  22. function add( byval a as integer, byval b as integer ) as integer
  23. return a + b
  24. end function
  25.  
  26. print add( 1, 2 )
  27.  
  28. type AddFn as function( byval as integer, byval as integer ) as integer
  29. dim padd as AddFn = @add
  30. print padd( 1, 2 )
  31.  
  32. ''
  33. '' 指针索引(与数组非常相似):
  34. ''
  35. '' 3个整数分配内存
  36. = callocate( sizeof(integer) * 3 )
  37.  
  38. p[0] = 123
  39. p[1] = 456
  40. p[2] = 789
  41. print p[0], p[1], p[2]
  42.  
  43. deallocate( p )
  44.  
  45. ''
  46. '' 以前的 peek():
  47. ''
  48. dim as any ptr address
  49. dim as byte dat(0 to 3) = { 123, 123, 123, 123 }
  50. dim as integer j = 12345
  51.  
  52. address = @dat(0)
  53. print peek( address )
  54.  
  55. address = @j
  56. print peek( integer, address )
  57.  
  58. ''
  59. '' 指针 to UDTs:
  60. ''
  61. type MyVector
  62. as integer x, y, z
  63. end type
  64.  
  65. dim as MyVector v
  66. dim as MyVector ptr pv = @v
  67. pv->= 1
  68. pv->= 2
  69. pv->= 3
  70.  
  71. print pv->x, pv->y, pv->z
  72. print (*pv).x, (*pv).y, (*pv).z
  73. with *pv
  74. print .x, .y, .z
  75. end with
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
vb.net 打印代碼
VB.NET自动操作其他程序(3)
【VFB】 多线程(VFB教程3
VBA的过程及参数详解
公历农历转换VB类
用VB写高效的图像处理程序
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服