c语言笔记(二)

gcc:

 

gcc -Wall hello.c -o hello
./hello

执行当前目录的程序要加 ./

gcc -Wall -c hello.c  编译成目标文件
gcc hello.o -o hello  使用link成执行文件


usr/include  usr/local/include  系统头文件目录

since int is the default return type, it could be omitted. (function)

c语言的string类型和全局变量 ???

strlen(s) 字符串的长度 不包含'/0'  <sting.h>

x *=y+1 == x = x*(y+1)

The operators -> and . are used to access members of structures

Character arrays are a special case of initialization; a string may be used instead of the braces and commas notation:
char pattern = "ould";
is a shorthand for the longer but equivalent
char pattern[] = { 'o', 'u', 'l', 'd', '/0' };
In this case, the array size is five (four characters plus the terminating '/0').

leading --- trailing

(*ip)++
The parentheses are necessary in this last example; without them,
the expression would increment ip instead of what it points to,
because unary operators like * and ++ associate right to left.

In evaluating a[i], C converts it to *(a+i) immediately; the two forms are equivalent
pa[i] is identical to *(pa+i). In short, an array-and-index expression is equivalent to one written as a pointer and offset

 

As formal parameters in a function definition,
char s[];  and  char *s;
are equivalent; we prefer the latter because it says more explicitly that the variable is a pointer.

Pointers and integers are not interchangeable.
Zero is the sole exception: the constant zero may be assigned to a pointer,
and a pointer may be compared with the constant zero. The symbolic constant NULL is often used in place of zero,
as a mnemonic to indicate more clearly that this is a special value for a pointer. NULL is defined in <stdio.h>.
We will use NULL henceforth.


char *name[] = { "Illegal month", "Jan", "Feb", "Mar" };  存放指针的数组


The declarations should be studied with some care. The fourth parameter of qsort is
int (*comp)(void *, void *)
which says that comp is a pointer to a function that has two void * arguments and returns an
int.
The use of comp in the line
if ((*comp)(v[i], v[left]) < 0)
is consistent with the declaration: comp is a pointer to a function, *comp is the function, and
(*comp)(v[i], v[left])
is the call to it. The parentheses are needed so the components are correctly associated;
without them,
int *comp(void *, void *) /* WRONG */
says that comp is a function returning a pointer to
different.

dcl dirdcl  ???? 没看懂

struct { ... } x, y, z;
is syntactically analogous to
int x, y, z;
struct maxpt = { 320, 200 };

The parentheses are necessary in (*pp).x because the precedence of the structure member operator . is higher then *. The expression *pp.x means *(pp.x), which is illegal here because x is not a pointer.
Pointers to structures are so frequently used that an alternative notation is provided as a shorthand. If p is a pointer to a structure, then
p->member-of-structure

The structure operators . and ->, together with () for function calls and [] for subscripts, are at the top of the precedence hierarchy and thus bind very tightly. For example, given the declaration
struct {
int len;
char *str;
} *p;
then
++p->len
increments len, not p, because the implied parenthesization is ++(p->len). Parentheses can be used to alter binding: (++p)->len increments p before accessing len, and (p++)->len increments p afterward. (This last set of parentheses is unnecessary.)
In the same way, *p->str fetches whatever str points to; *p->str++ increments str after accessing whatever it points to (just like *s++); (*p->str)++ increments whatever str points to; and *p++->str increments p after accessing whatever str points to.

With lseek, it is possible to treat files more or less like arrays, at the price of slower access.

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值