C Pointer to pointer

Source: Internet
Author: User

Pointers to pointers are a form of multilevel indirection, or a pointer chain. Typically, a pointer contains the address of a variable. When we define a pointer to a pointer, the first pointer contains the address of the second pointer, and the second pointer points to the position that contains the actual value.

A pointer variable pointing to a pointer must be declared as follows, placing two asterisks before the variable name. For example, the following declares a pointer to the INT type pointer:

int * *var;

When a target value is indirectly directed to another pointer by one pointer, access to the value requires the use of two asterisk operators, as shown in the following example:

1#include <stdio.h>2  3 intMain ()4 {5    int  var;6    int*ptr;7    int**pptr;8 9    var= the;Ten  One    /*get the address of Var*/ APTR = &var; -  -    /*Use the operator & get the address of PTR*/ thePptr = &ptr; -  -    /*get a value using Pptr*/ -printf"Value of var =%d\n",var ); +printf"Value available at *ptr =%d\n", *ptr); -printf"Value available at **pptr =%d\n", **pptr); +  A    return 0; at}

When the above code is compiled and executed, it produces the following results:

var  the   about

C Pointer to pointer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.