Thread: pointer to a pointer

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Okay, let's start with a simpler example.

    Code:
    #include <stdio.h>
    
    void GetAirplaneType(char **dest)
    {
        printf("print of the pointer value inside the function: %s %p\n", *dest, (void*)(*dest));
        char new_dest[] = "Big Deal";
        *dest = new_dest;
    }
    
    
    int main()
    {
        // Let's start with an array, not a const char*.
        char des[100] = "New York";
        printf("print of the pointer value outside the function: %s %p\n", des, (void*)des);
    
        // Create a pointer that is pointing to the variable des.
        char *n_des = des;
      
        GetAirplaneType(&n_des);
    
        printf("print of the pointer value outside the function: %s %p\n", n_des, (void*)n_des);
    
    }
    Note: You probably shouldn't be playing with pointers but instead copy the C-strings.

    Code:
    #include <stdio.h>
    #include <string.h>
    
    void GetAirplaneType(char *dest)
    {
        strcpy(dest, "Big Deal");
    }
    
    
    int main()
    {
        char des[100] = "New York";
        printf("print of the pointer value before the function: %s \n", des);
    
        GetAirplaneType(des);
    
        printf("print of the value after the function: %s \n", des);
    
    }

  2. #2
    Registered User
    Join Date
    Oct 2018
    Posts
    10
    thank you guys very more for explanations!
    im new here, how can i thumbs up for you guys?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 08-05-2018, 12:14 AM
  2. Replies: 4
    Last Post: 08-18-2015, 03:13 PM
  3. Replies: 8
    Last Post: 03-01-2015, 12:39 AM
  4. Replies: 3
    Last Post: 10-30-2009, 04:41 PM
  5. Replies: 4
    Last Post: 08-27-2007, 11:51 PM

Tags for this Thread