LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

Pointer to Pointer

Last updated at Posted at 2015-03-16

  char *lines[] = {
    "abcef", "def", "gh"
  };
  char **table = lines;
  table[0] = "hello";


  printf("%s\n%s\n%s\n", table[0], table[1], table[2]); 

  size_t sz = sizeof(lines);   /* linesに必要な全バイト? */
    sz /= sizeof(*lines);      /* char* のサイズ sizeof(line[0][0]) */  
    printf("%d\n", sz);        /* 要素数 */


  char* str1 = "abc";
  char str2[] = "def";
  char* p = str2;

  char** hoge;

  // *hoge = str2 : 文字列定数"def"のアドレスを代入。あぶない。
  // hoge = &str2 : 型が違う。左辺は配列へのポインタ"char (*hoge)[]" が必要
  hoge = &p;
  hoge = &str1;
  hoge = str2;



0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up