静态变量
#include<stdio.h>
int* AA()
{
static a = 100;
a++;
return &a;
}
int main()
{
int* p = AA();
printf("%d\n",*AA());
printf("%d\n",*AA());
printf("%d\n",*AA());
printf("%d\n",*AA());
return 0;
}
字符串
#include<stdio.h>
#include<string.h>
int main()
{
char str[5] = {'a','b','c','d'};
char str1[] = "abcde";
char* str2 = "abcde";
str1[1] = 'B';
printf("%d\n",sizeof(str1));
printf("%d\n",strlen(str1));
printf("%d\n", sizeof(str2));
printf("%d\n", strlen(str2));
return 0;
}
strcpy
#include<stdio.h>
#include<string.h>
int MyStrlen(char * str)
{
int nCount = 0;
while (*str != '\0')
{
nCount++;
str++;
}
return nCount;
}
char* MyStrcpy(char* str1, char* str2)
{
char* pMark = str1;
while (*str2 != '\0')
{
*str1 = *str2;
str1++;
str2++;
}
*str1 = '\0';
return pMark;
}
int main()
{
char str[5];
char str1[] = "abcd";
MyStrcpy(str, str1);
printf("%s\n",str);
strncpy_s(str, sizeof(str) / sizeof(str[0]), str1, 2);
printf("%s\n",str);
return 0;
}