NDK04_C:const、typedef、union共用体
NDK開発要約
1 const
const char*,char const*,char*const,char const*const const:定数=final
二typedef
別名です.javaエージェントのように新しいデータ型は作成されません.既存のタイプに別名が作成されています.
さんunionきょうようたい
同じメモリ位置に異なるデータ型のコモンを格納するために使用されるメモリは、コモン内の最大のメンバーがメモリを共有するのに十分で、メモリアドレスが一致している必要があります.最近定義されたものが有効です
Demo
実行結果:
a: 0x8ff660, b: 0x8ff660, c: 0x8ff660 a: 1067030938, b: ? c: 1.200000
四Demo
lsn04
1 const
const char*,char const*,char*const,char const*const const:定数=final
//
//P const char
char str[] = "hello";
const char *p = str;
str[0] = 'c'; //
p[0] = 'c'; // const char
//
// p david,
// david ,
// p lance,lance 。
p = "12345";
// const char *
char const *p1;
//p2 const char
char * const p2 = str;
p2[0] = 'd'; //
p2 = "12345"; //
//p3 const
// const char
// const char * char * const
char const* const p3 = str;
二typedef
別名です.javaエージェントのように新しいデータ型は作成されません.既存のタイプに別名が作成されています.
typedef int _in;
typedef char * string;
typedef int(*PFI)(char *, char *);
typedef Tnode * Treeptr;
typedef struct Tnode {
char *word;
int count;
Treeptr left;
Treeptr right;
} BinaryTreeNode;
int fun(char *, char *) {
return 0;
}
int test4() {
_in a = 20;
printf("%d
", a);
string str;
str = (char *)"hello world";
PFI fp;
fp = fun;
char * ch;
ch = (char *)"hello world";
BinaryTreeNode* node;
node = (BinaryTreeNode *)malloc(sizeof(BinaryTreeNode));
system("pause");
return 0;
}
さんunionきょうようたい
同じメモリ位置に異なるデータ型のコモンを格納するために使用されるメモリは、コモン内の最大のメンバーがメモリを共有するのに十分で、メモリアドレスが一致している必要があります.最近定義されたものが有効です
// 4
union Data
{
int i;
short j;
}
union Data data;
data.i = 1;
//i
data.j = 1.1f;
Demo
union MyUnion {
int a;
char b;
float c;
};
int test4() {
MyUnion unio;
unio.a = 10;
unio.b = 'a';
unio.c = 1.2f;
printf("a: %#x, b: %#x, c: %#x
", &unio.a, &unio.b, &unio.c);
printf("a: %d, b: %c, c: %f
", unio.a, unio.b, unio.c);
system("pause");
return 0;
}
実行結果:
a: 0x8ff660, b: 0x8ff660, c: 0x8ff660 a: 1067030938, b: ? c: 1.200000
四Demo
lsn04