指向char的指针 [英] pointer-to-pointer to char
问题描述
可以编译以下代码。但是当我运行它时,它会导致
分段错误。
int main(){
char ** c1;
* c1 =" HOW" ;; // LINE1
++(* c1);
* c1 =" ARE";
++(* c1);
* c1 =" YOU";
}
c1是指针指向-pointer to char。如何将c1初始化为三个
字符串:HOW,ARE,你?
非常感谢。
The following code can be compiled. But When I run it, it causes
"Segmentation fault".
int main(){
char **c1;
*c1 = "HOW"; // LINE1
++(*c1);
*c1 = "ARE";
++(*c1);
*c1 = "YOU";
}
c1 is a pointer-to-pointer to char. How to initialize c1 to three
strings: "HOW", "ARE", "YOU"?
Thanks a lot.
推荐答案
Jack写道:
可以编译以下代码。但是当我运行它时,它会导致分段错误。
int main(){
char ** c1;
* c1 =怎么样; // LINE1
c1并没有指向任何东西......
c1是指向char的指针。如何将c1初始化为三个
字符串:HOW,ARE,YOU?
The following code can be compiled. But When I run it, it causes
"Segmentation fault".
int main(){
char **c1;
*c1 = "HOW"; // LINE1
c1 doesn''t point to anything...
c1 is a pointer-to-pointer to char. How to initialize c1 to three
strings: "HOW", "ARE", "YOU"?
char * c1 [] = {" HOW" ,ARE,你, };
-
Ian Collins。
char *c1[] = { "HOW", "ARE", "YOU" };
--
Ian Collins.
Ian Collins写道:
Ian Collins wrote:
杰克写道:
Jack wrote:
可以编译以下代码。但是当我运行它时,它会导致分段错误。
int main(){
char ** c1;
* c1 =怎么样; // LINE1
The following code can be compiled. But When I run it, it causes
"Segmentation fault".
int main(){
char **c1;
*c1 = "HOW"; // LINE1
c1没有指向任何东西......
c1 doesn''t point to anything...
c1是指向char的指针。如何将c1初始化为三个
字符串:HOW,ARE,你?
c1 is a pointer-to-pointer to char. How to initialize c1 to three
strings: "HOW", "ARE", "YOU"?
char * c1 [] = {" HOW" ,ARE,你, };
char *c1[] = { "HOW", "ARE", "YOU" };
我应该说
const char * c1 [] = {" HOW"," ARE"," YOU" };
-
Ian Collins。
I should have said
const char *c1[] = { "HOW", "ARE", "YOU" };
--
Ian Collins.
Jack写道:
可以编译以下代码。但是当我运行它时,它会导致分段错误。
int main(){
char ** c1;
* c1 =怎么样; // LINE1
轰!崩溃和烧伤! c1未初始化且* c1为垃圾。
++(* c1);
* c1 =" ARE";
++(* c1);
* c1 =你;
}
c1是指向char的指针。如何将c1初始化为三个
字符串:HOW,ARE,你?
非常感谢。
The following code can be compiled. But When I run it, it causes
"Segmentation fault".
int main(){
char **c1;
*c1 = "HOW"; // LINE1
Boom! Crash and burn! c1 is not initialized and *c1 is garbage.
++(*c1);
*c1 = "ARE";
++(*c1);
*c1 = "YOU";
}
c1 is a pointer-to-pointer to char. How to initialize c1 to three
strings: "HOW", "ARE", "YOU"?
Thanks a lot.
#include< stdlib.h>
char ** c1 = malloc(3 * sizeof * c1);
c1 [0] ="如何;
c1 [1] =" ARE";
c1 [2] =" YOU";
-
Joe Wright
所有东西都应尽可能简单,但不能简单。
--- Albert爱因斯坦---
#include <stdlib.h>
char **c1 = malloc(3 * sizeof *c1);
c1[0] = "HOW";
c1[1] = "ARE";
c1[2] = "YOU";
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
这篇关于指向char的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!