c# include <stdio.h> # include <stdlib.h> int main() { int n = 999; char ch = 'a'; short int w = 'BA'; int *pn = NULL; char *pch = NULL; short int *pw = NULL; void *pv = NULL; pn = &n; pch = &ch; pw = &w; //有解释方式的指针给以赋值给void指针 pv = pn; //不能将void指针赋值给有解释方式的指针 //pn = pv system("pause"); return 0; }
c# include <stdio.h> # include <stdlib.h> # include <string.h> char *foo(char *psz) { char *szBuf = "Hello World!"; return szBuf; //返回的是值 } int main() { char *psz = NULL; char szHello[] = "Hello World!"; printf("%d\r\n",sizeof("Hello")); printf("%d\r\n",sizeof(szHello)); psz = foo(szHello); printf(psz); //printf会将foo栈空间覆盖,所以不确定输出什么 system("pause"); return 0; }
c# include <stdio.h> # include <stdlib.h> # include <string.h> char *fun() { int n = 999; return &n; } int main() { int *pn = fun(); *pn = 666; printf("%d\r\n",*pn);//666,printf还没来的及占用,就把值传递了 printf("%d\r\n",*pn);//为止 system("pause"); return 0; }
c# include <stdio.h> # include <stdlib.h> # include <tchar.h> # ifdef __T # undef __T # endif # define __T(x) L ## x # ifdef _T # undef _T # endif # define _T(x) __T(x) # define MYHELLO "Hello" int _tmain() { wchar_t wTest[] = __T(MYHELLO); //wchar_t wTest[] = LMYHELLO; wchar_t wTest[] = _T(MYHELLO);//_T解决对宏字符串的处理 //wchar_t wTest[] = L"Hello"; system("pause"); return 0; }
本文作者:Na1r
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!