Initializing a pointer to a structure

前端 未结 6 2200
半阙折子戏
半阙折子戏 2020-12-18 00:32

another linked question is Segmentation fault while using strcpy()?

I have a structure:

struct thread_data{    
    char *incall[10];
    int syscall         


        
6条回答
  •  死守一世寂寞
    2020-12-18 00:48

    The corresponding struct initialiser can look like this:

    struct thread_data a = {
      .incall = {"a", "b", "c", "d", "e"},
      .arg_no = 5,
      .client_socket = 3
    };
    

    Then you can assign the address of this to a pointer:

    struct thread_data *b = &a;
    

提交回复
热议问题