layout: post
真的是太欣赏c的速度了,但如果你连c的指针计算都搞不定,那就好比你活生生的错过了绝世美女,如果真的是那样,人生就太遗憾了。
double free:free已经free的内存。
访问已经释放的内存
https://en.wikibooks.org/wiki/C_Programming/Simple_input_and_output
In Standard C there are four basic data types. They are int, char, float, and double.
printf
%d int
%f float
%c char
%s string
%p pointer
scanf
it might read as: "Read in an integer from the user and store it at the address of variable a ".
scanf("%d", &a);
scanf("%s", a);
This is because, whenever you use a format specifier for a string (%s), the variable that you use to store the value will be an array and, the array names (in this case - a) themselves point out to their base address and hence, the address of operator is not required.
& Address-of; value is the location of the operand(取地址)
* Contents-of; value is what is stored at the location(取内容)
或与非
||
&&
!
if (conditions)
{
// do something
}
else if (conditions)
{
// do otherthing
}
else
{
// do something
}
int i = 0;
for(i=0;i<100;i++)
{
printf("%d", i);
}
int i = 0;
while (i < 100)
{
//do something
i++;
}
do{
}while(condition)
break 跳出循环
continue 跳出本次循环
Start:
if (!''cond1'') goto End;
S;
if (''cond2'') goto End;
T;
goto Start;
End:
/* ... */
switch (something) {
case 2:
case 3:
case 4:
/* some statements to execute for 2, 3 or 4 */
break;
case 1:
default:
/* some statements to execute for 1 or other than 2,3,and 4 */
break;
}
指针是地址
指针变量是用来存放指针的变量
空指针的存放的值为0
#include <stdio.h>
int main () {
int *ptr = NULL;
printf("The value of ptr is : %x\n", ptr );
return 0;
}
When the above code is compiled and executed, it produces the following result −
The value of ptr is 0
指针算数
https://www.tutorialspoint.com/cprogramming/c_pointer_arithmetic.htm
有四种算数操作符可以应用到指针变量上面,++
, --
, +
, -
sizeof
https://www.tutorialspoint.com/c_standard_library/stdio_h.htm
void *malloc(size_t size); //使用malloc分配的内存是没有初始化的
void *calloc(size_t nitems, size_t size)
int puts(const char *str)
printf()
scanf()
sprintf()
sprintf_s()
snprintf()
snprintf_s()
strcpy()
strlen()
strncpy()
strncpy_s()
memset()