一、strcpy()与strncpy()
strcpy():strcpy(dest,src); strcpy把src所指向以'\0'结尾的字符串复制到dest所指的数组中,返回指向dest的指针。
当sizeof(dest)>=sizeof(src)时,拷贝正确,并在dest字符串后面加入'\0';
当sizeof(dest)
strncpy():strncpy(dest,src,...
分类:
其他好文 时间:
2014-10-06 17:52:50
阅读次数:
186
#includeusing namespace std;int main(){ //memcpy函数 char d[20]; //声明数组 char *str="Hellow word"; memcpy(d,str,strlen(str)); d[strlen(str)]=0; //末尾添加0 表示...
分类:
其他好文 时间:
2014-10-06 17:28:00
阅读次数:
221
int a[3];a 和 &a 的地址一样的。a+1 == a + 1*sizeof(int);跳跃是一个数组元素大小&a+1 == a + 3*sizeof(int);跳跃是整个数组大小#include intmain(){ char * a[] = {"hello","the","world"}...
分类:
其他好文 时间:
2014-10-03 23:53:55
阅读次数:
292
堆和栈的区别一个由C/C++编译的程序占用的内存分为以下几个部分1、栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。2、堆区(heap) — 一般由程序员分配释放, 若程序员不释放,程序结束时可能由OS回收 。注意它与数据结构中的堆是两...
分类:
其他好文 时间:
2014-10-03 20:25:55
阅读次数:
240
/*
数位dp,记忆化搜索写法
注意memset(dp,-1,sizeof(dp))是放在外面的,这样保证每次搜索时存的值满足下一次也可以用;
如果放在里面就会超时
每个长度有10000种状态
*/
#include
#include
#define N 20
int len,digit[N],dp[N][10000];
int dfs(int len,int cnt,int ok) {
...
分类:
其他好文 时间:
2014-10-03 20:21:05
阅读次数:
157
二者有本质上的区别 从定义可以知道sizeof只是一个operator,而strlen()则是定义一个定义在中的函数;所以sizeof(string)是在计算string所占用的内存,包含了'\0'结尾符,strlen(string)则是用来计算字符串的长度,省略了'\0'。 详见:http://c...
分类:
其他好文 时间:
2014-10-03 18:40:14
阅读次数:
194
http://blog.csdn.net/yysdsyl/article/details/1885795看了《C++ 对像模型》的人,往往会误以为编译器填充是按照计算机字长填充的,如下:class A{ double a; char b;};sizeof(A) == ? 不了解填充的人会以为是9,看...
分类:
其他好文 时间:
2014-10-02 21:36:13
阅读次数:
190
动态分配内存:头文件 stdlib.h malloc:分配内存 calloc:分配内存,并清零 realloc:调整已分配的内存块大小 演示样例: int *p=(int *) malloc(3*sizeof(int));//分配内存,成功返回首地址,失败返回NULL free(p);p=NUL.....
分类:
其他好文 时间:
2014-10-02 19:39:33
阅读次数:
179
自己写的#includebool check(int a[],int start,int end);void main(){// int a[]={5,7,6,9,11,10,8}; int a[]={7,4,6,5}; int len=sizeof(a)/sizeof(int); if(check...
分类:
其他好文 时间:
2014-10-02 18:33:23
阅读次数:
130
#include#include#includeusing namespace std;struct s1{ char a; char b; char c; };struct s2{ int a; char b; short c; ...
分类:
其他好文 时间:
2014-10-01 20:02:41
阅读次数:
162