易截截图软件、单文件、免安装、纯绿色、仅160KB

指针变量的定义和初始化[c][code]


原帖:
http://hi.baidu.com/pepsi360/blog/item/cc74be4412cf6789b3b7dcd4.html
#include <stdio.h>
struct Node
{
    int a;
    char b[10];
     Node *next;
};
main(void)
{
    char   *p=NULL; //"define NULL 0" included in <stdio.h>
    int    *q=0; //值0是唯一能够直接赋给指针变量的整数值
    double *d;
     Node *pNode=NULL;
     d=NULL;
    return 0;
}
 
以上代码在VC环境下调试运行。
step1. 运行完语句Node *pNode=NULL;后:
Name       Value
+ &p        0x0012ff7c ""
+ &q        0x0012ff78 ""
+ &d        0x0012ff74 ""
+ &pNode 0x0012ff70 ""
Memory:
0012FF66 CC CC CC CC CC CC CC CC CC CC 00 烫烫烫烫烫.
0012FF71 00 00 00 CC CC CC CC 00 00 00 00 ...烫烫....
0012FF7C 00 00 00 00 C0 FF 12 00 39 11 40 ........9.@
step2. 运行完语句d=NULL;后:
Name       Value
+ &p        0x0012ff7c ""
+ &q        0x0012ff78 ""
+ &d        0x0012ff74 ""
+ &pNode 0x0012ff70 ""
Memory:
0012FF66 CC CC CC CC CC CC CC CC CC CC 00 烫烫烫烫烫.
0012FF71 00 00 00 00 00 00 00 00 00 00 00 ...烫烫....
0012FF7C 00 00 00 00 C0 FF 12 00 39 11 40 ........9.@
在Turbo C中的代码如下:
#include <stdio.h>
struct Node
{
    int a;
    char b[10];
    struct Node *next; /* struct不能少 */
};
main(void)
{
    char   *p=NULL; /* "define NULL 0" included in <stdio.h> */
    int    *q=0;
  &


相关文档:

读《C和指针》笔记摘要【6】

2010-04-09
第十五章    输入/输出函数
1、错误报告
perror函数     void perror( char const *message);
2、终止执行
void exit( int status );    原型定义于stdlib.h
其中status参数返回给操作系统,用于提示程序是否正常完成,这个值和main函数返回的整型状态 ......

C/C++动态数组初始化

      vs2008里面定义全局变量:
      extern bool *g_previewStatusArray = new bool[EQUIPMENT_AMOUNT]();  //被默认初始化为false
      但是如果不加上后面的括号,则默认初始化为true。 ......

ARM中C和汇编混合编程及示例

1. 在C语言中内嵌汇编
在C中内嵌的汇编指令包含大部分的ARM和Thumb指令,不过其使用与汇编文件中的指令有些不同,存在一些限制,主要有下面几个方面:
 
a. 不能直接向PC寄存器赋值,程序跳转要使用B或者BL指令
b. 在使用物理寄存器时,不要使用过于复杂的C表达式,避免物理寄存器冲突
c. R12和R13可能被编译 ......

C的enum struct 以及 Java的enum

 在c中enum的使用和struct很像
enum name{
a,b,c
};

 
struct name{
int a;
int b;
char c;
};

 
or
 
typedef struct{
int a;
int b;
char c;
}Name;

使用的时候都要先声明变量
 
enum name n1,n2,n3;
n1=a;
n2=b;
n3=enum name(3-1);
struct name sn1,sn2;
s ......

C Error: mixed declaration and codes.

/*FIXME
ISO C如果你在main()中写代码的中间定义了一个对于main而言的全局变量,就会报出这个错误。
*/
把这个变量定义到main函数中的最前方,就会修正这个错误。
而且为了防止出错,设定的指针之后再有参数传入malloc之后立即对于指针予以空间的创建。防止出现指针未初始化从而引起将来赋值的时候将该值覆盖了已经为本 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号