码迷,mamicode.com
首页 > 其他好文 > 详细

void*指针的一些冷知识

时间:2015-08-27 07:04:27      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

Pointer (computer programming)
Pointer arithmetic cannot be performed on void pointers because the void type has no size, and thus the pointed address can not be added to, although gcc and other compilers will perform byte arithmetic on void* as a non-standard extension, treating it as if it were char *.

Pointer Arith
In GNU C, addition and subtraction operations are supported on pointers to void and on pointers to functions. This is done by treating the size of a void or of a function as 1.

 

so...sizeof(void *) = sizeof(char *) = 4.

by the way, sizeof(char) = 1.

 

如果一个变量point的类型是void*,他在point++ ,point = point + 1 等操作的时候,是往下数1个字节。因为void*会被默认当作char*

 

void*指针的一些冷知识

标签:

原文地址:http://www.cnblogs.com/sunfishgao/p/4762177.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!