代码之家  ›  专栏  ›  技术社区  ›  Cheetah

如何从char获取char*

  •  4
  • Cheetah  · 技术社区  · 15 年前

    我了解&用于引用对象的地址,因此 &char* = char** . 有没有办法把这个倒过来 char* char** ?

    所以我有:

    char** str; //assigned to and memory allocated somewhere
    
    printf ("%s", str); //here I want to print the string.
    

    我该怎么做呢?

    3 回复  |  直到 15 年前
        1
  •  17
  •   Jacob Relkin    15 年前

    dereference operator

    char** str; //assigned to and memory allocated somewhere
    
    printf ("%s", *str); //here I want to print the string.
    
        2
  •  5
  •   Alex Reynolds    15 年前

    str

    print ("%s", *str); /* assuming *str is null-terminated */
    
        3
  •  3
  •   peoro    15 年前

    T* T *

    char* (char*)*

    [] *s s[0] s[n] *(s+n)

    char** s printf( "%s", *str )

    for( i = 0; i < N; ++ i ) print( "%s\n", str[i] );
    

     for( i = 0; i < N; ++ i ) print( "%s\n", *(str+i) );