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

C专家编程学习 1

时间:2014-05-02 15:12:33      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:style   class   code   tar   ext   color   

1.C语言的基本数据类型直接与底层硬件相对应。

2#define 是可能出现问题

1
2
3
4
5
#define a(y) a_ex(y)
a(x)被扩展为 a_ex(x)
 
#define a (y) a_ex(y)
a(x)被扩展为 (y) a_ex(y)(x)

#define宏的用法

1.简单宏定义

1
#define a y

将文件中的 a 全部换成 y

为了避免出现问题,要将宏展开,根据运算符的优先级判断是否是需要的运算顺序。

2.带参数的宏定义

1
2
#define a(y) a_ex(y)
a(x)被扩展为 a_ex(x)

#define a(y) a_ex(y) 中的a(y)的中间不能带空格否则成了简单的宏替换了

1
2
#define a (y) a_ex(y)
a(x)被扩展为 (y) a_ex(y)(x)

有空格,为简单的宏替换, a 换成 (y) a_ex(y)

a(x)替换后成了(y) a_ex(y)(x)


3.const

1
2
3
4
5
6
7
8
#include <stdio.h>
 
void main()
{
char *pa;
const char *pb;
pa=pb;
}
1
C:\Documents and Settings\CHEN\桌面\ff\main.c|7|warning: assignment discards ‘const‘ qualifier from pointer target type [enabled by default]|
1
2
3
4
5
6
7
8
#include <stdio.h>
 
void main()
{
char *pa;
const char *pb;
pb=pa;
}

赋值合法

两操作数都是指向有限定符或无限定符的指针,则左边的指针所指向的类型必须具有右边所指向类型的全部限定符。

pa 为指向char 类型的指针,pb 是指向const char 类型的指针限定符为const

pa=pb 左边限定符为无,右边为const 不符合规则的。

pb=pa 左边限定符为const ,右边限定符为无,左边具有右边的全部限定符,故是符合规则的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
 
void main()
{
char *pa;
const char *pb;
char **pc;
const char **pd;
pb=pa;
 
pc=&(pa);
pd=&(pb);
pd=pc;
}

pc为指针,指针指向指针,指针指向char

pd为指针,指针指向指针,指针指向const char

pc pd 指向的均为没有限定符的指针,且该指针指向的类型不一样。


4.算术转换

整型升级

int char short  int型位段,,包括他们的有符号和无符号变型,以及枚举类型,在表达式中转化为 int 或 unsiged int 

寻常算术转换











C专家编程学习 1,布布扣,bubuko.com

C专家编程学习 1

标签:style   class   code   tar   ext   color   

原文地址:http://www.cnblogs.com/chen-/p/3703791.html

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