Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Q166】在C语言中,void * 是什么意思 #167

Open
shfshanyue opened this issue Jan 9, 2020 · 1 comment
Open

【Q166】在C语言中,void * 是什么意思 #167

shfshanyue opened this issue Jan 9, 2020 · 1 comment
Labels

Comments

@shfshanyue
Copy link
Owner

No description provided.

@shfshanyue shfshanyue added the c label Jan 9, 2020
@shfshanyue
Copy link
Owner Author

void 指无类型,常用在函数前,表示什么也不用返回。

* 代表一个指针,如 int *p 代表指针 p 指向一个整型,char *s 代表指针 s 指向一个字符串的首地址。

void * 代表一个可能指向任何类型的指针,如下代码所示:

#include <stdio.h>

int main() {
  void *p;

  // 使用它装一个整数
  int a = 3;
  p = &a;
  printf("%d", *(int *)p);

  // 使用它装一个字符串
  char s[] = "hello, world";
  p = s;
  printf("%s", p);
  return 0;
}

相关问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant