這么基礎的居然不清楚!
// 01_strcpy.cpp : 定義控制臺應用程序的入口點。
//
#include "stdafx.h"
#include <assert.h>
char* my_strcpy(char* strDest, const char* strSrc)
{
assert(strDest != NULL && strSrc != NULL);
char* address = strDest;
while ( (*strDest++ = *strSrc++) != '\0' )
NULL;
return address;
}
int _tmain(int argc, _TCHAR* argv[])
{
char strDest[32] = {0};
my_strcpy(strDest, "Hello World");
printf("%s\n", strDest);
const char* p = "Hello"; // p指向的內存單元不可修改
p++;
printf("%c\n", p[0]); // e
// p[0] = 'a'; // error C3892: “p”: 不能給常量賦值
char* const q = "world"; // q指針本身為常量。
// q++; // error C3892: “q”: 不能給常量賦值
const char* const r = "rrr"; // r指向的內存單元不可修改,r指針本身為常量;
int value = 4;
value = 5;
const int iVal = 3;
//iVal = 2; // error C3892: “iVal”: 不能給常量賦值
return 0;
}
posted on 2011-02-16 17:01
七星重劍 閱讀(1997)
評論(0) 編輯 收藏 引用 所屬分類:
PL--c/c++