char*,char*,char*[]の初期化方法


#include "pch.h"
#include 
#include
int len(char*a) {
	printf("%s
", a); return strlen(a); } int main() { char**t; char a[4]; const char*c = "asd"; strcpy_s(a, c); printf("%d
", len(a)); t[0] = a; printf("%s", t[0]); return 0; } //

char**の場合、2次元のchar配列であり、t[0]は最初の文字列と見なすことができる.
ただし、tは初期化されていないため、t[0]の存在は保証されないため、char**を初期化する際には、t[0]の存在を保証するためにchar*t[4]を用いなければならない
#include "pch.h"
#include 
#include
int len(char*a) {
	printf("%s
", a); return strlen(a); } int main() { char*t[4]; char a[4]; const char*c = "asd"; strcpy_s(a, c); printf("%d
", len(a)); t[0] = a; printf("%s", t[0]); return 0; } //

char*aの初期化については、同じようにchar a[4]で4つあることを教える必要はなく、彼に値を与えることはできません.
またここで注意したいのは、char*a=「ttt」はできません.「ttt」はconst char*なので、修正できません.
char a[4]=「ttt」なら可能ですが、彼はaの大きさを知っているので、まず大きさ4のchar配列を作成してから「ttt」を付与することができます.彼に大きさを教えなければ、自然に彼にこのように与えることはできません.
 
最後に、const char*の文字列をchar*に割り当てるには、=番号は使えず、strcpyしか使えません!!!