Why we used double and triple pointer in objective-C or C language?

I confused when i want to take single pointer and when should i take double pointer? In following structure what exactly did?

struct objc_class {
    Class isa;
    Class super_class;
    const char *name;
    long version;
    long info;
    long instance_size;
    struct objc_ivar_list *ivars;
    struct objc_method_list **methodLists;
    struct objc_cache *cache;
    struct objc_protocol_list *protocols;

Why we use the methodLists double pointer?


int sqlite3_get_table(
      sqlite3 *db,         
      const char *zSql,    
      char ***pazResult,   
      int *pnRow,          
      int *pnColumn,       
      char **pzErrmsg      

In above scenario what will be meaning of triple pointer char ***pazResult?

Well, in C at least, double-pointers are commonly used for 2D arrays. The most common 2D array is probably an array of C strings (char*'s). Double pointers are also sometimes employed to pass pointers to functions by reference, but this is unlikely to be the use in the code sample you posted.

According to the name methodLists I would guess that this is an array of lists. A (linked) list in C is commonly represented by a pointer to a node, which objc_method_list could be. An array of such lists is then implemented with a double pointer.

Prerequisite : Pointers in C and C++ . We already know that a pointer points to a location in memory and thus used to store the address of variables. So, when we define a pointer to pointer. The first pointer is used to store the address of the variable. And the second pointer is used to store the address of the first pointer.

It's probably not the case in the code that you referenced, but you also need a double pointer any time you want to pass a pointer to a function and have changes to that pointer be reflected outside the scope of that function.

For example, if you were trying to rewrite the strcpy function so that the user did not have to allocate memory for the source string, you might try something like the following:

void MyStrcpy(char* dst, char* src){ 
  dst = (char*)malloc(sizeof(char)*(strlen(src)+1));
  for(int i=0;i<=strlen(src);i++)
    dst[i] = src[i];
  printf("src: %s ", src);
  printf("dst: %s\n\n", dst);

If you were then to call that function,

int main() {
     char *foo = "foo";
     char *newPtr;

     MyStrcpy(newPtr, foo);

     printf("foo: %s ", foo);
     printf("new: %s\n", newPtr);

your output would be as follows:

src: foo dst: foo

foo: foo new:

You might also get a seg fault when trying to print newPtr, depending your system. The reason for this behavior is the exact same as the reason you wouldn't expect a change to an int that was passed by value to a function to be reflected outside of that function: what you are passing to MyStrcpy is simply the memory address that newPtr references. When you malloc the space for dst inside the function, you are changing the address dst points to. This change will not be reflected outside of the scope of MyStrcpy!

Instead, if you wanted newPtr to point to the new allocated chunk of memory, you need to have dst be a pointer to a pointer, a char **.

void MyStrcpy(char** dst, char* src){ 
  *dst = (char*)malloc(sizeof(char)*(strlen(src)+1));
  for(int i=0;i<=strlen(src);i++)
    (*dst)[i] = src[i];
  printf("src: %s ", src);
  printf("dst: %s\n\n", *dst);

Now, if you were to call that function:

int main() {
  char *foo = "foo";
  char *newPtr;

  MyStrcpy(&newPtr, foo);

  printf("foo: %s ", foo);
  printf("new: %s\n", newPtr);

You would get your expected output:

src: foo dst: foo

foo: foo new: foo

Hope that helps!

Objective-C - Pointer arithmetic. There are four arithmetic operators that can be used on pointers: ++, --, +, - 2: Objective-C - Array of pointers. You can define arrays to hold a number of pointers. 3: Objective-C - Pointer to pointer. Objective-C allows you to have pointer on a pointer and so on. 4: Passing pointers to functions in Objective-C

In programming, a variable is basically a container used to hold data. The data itself can be anything from a simple number to the lyrics and metadata about a song. When we create a variable in Objective-C, we usually specify what kind of data it will hold. This is known as statically typing the data. Blocks of memory in the computer are

In the most general case a double pointer is a pointer to a list of pointers.

Multiple indirect pointers are a bit of a brain-twister in "C", as the language isnt much help with the syntax or semantics or run-time behavior of these thingys. Basically, you want to use pointers as a shortcut to moving or passing large objects. You want a pointer-to-a-pointer when you want to have a way of modifying the first pointer.

In general pointer is used to hold the address of another variable. What if we need to hold the address of pointer ,in that case we use double pointer. When we want to hold the address of double pointer we use triple pointer.

Pointer to Pointer in C Programming Declaration : Double Pointer int **ptr2ptr; Consider the Following Example : int num = 45 , *ptr , **ptr2ptr ; ptr = &num; ptr2ptr = &ptr; What is Pointer to Pointer ? Double (**) is used to denote the double Pointer Pointer Stores the address of the Variable Double …

We already know that a pointer holds the address of another variable of same type. When a pointer holds the address of another pointer then such type of pointer is known as pointer-to-pointer or double pointer. In this guide, we will learn what is a double pointer, how to declare them and how to use them in C programming.

Pointers (Explanation in terms of memory) Pointers are a powerful and dangerous(if not handled properly) feature of C. In more simple terms Pointers "points" to locations in memory.

Now we can use a typedef to create a named function pointer type called printer: typedef void (*printer_t)(int); This creates a type, named printer_t for a pointer to a function that takes a single int argument and returns nothing, which matches the signature of the functions we have above. To use it we create a variable of the created type and