Level 2 pointer

Source: Internet
Author: User

Objective: allocate a memory segment for storing pointers.

Code:

# Include <stdio. h> # include <stdlib. h> void test (char ** P, char * STR, char * str2) {printf ("P: % P \ n", P ); /* P points to the memory start address allocated by malloc x */printf ("& P: % P \ n", & P ); /* & P is the input parameter P's own address X2 */printf ("* P: % P \ n", * P ); /** P: NULL */* P = STR; printf ("* P: % P \ n", * P ); /** P is the STR address */P ++ at this time;/* offset a pointer type to X + 4 */printf ("P: % P \ n ", p); printf ("& P: % P \ n", & P); * P = str2; printf ("* p + 1: % P \ n ", * P);/** P is the str2 address */} int main () {char * STR = "ABC"; char * str2 = "abcdef "; printf ("str: % P \ n", STR); printf ("str2: % P \ n", str2 ); char ** P = malloc (8 * sizeof (char *); printf ("P: % P \ n", P ); /* P points to the memory start address allocated by malloc x */printf ("& P: % P \ n", & P ); /* & P is the address of the pointer Variable P itself X1 */printf ("* P: % P \ n", * P ); /** P is null at this time */test (P, STR, str2); printf ("P: % P \ n", P); printf ("& P: % P \ n ", & P); printf (" * P: % P \ n ", * P);/* the address of Str */printf (" P: % P \ n ", * (p + 1);/* the address of str2 */
Printf ("P: % P \ n", P [1]);/* the address of str2 at this time, the same as * (p + 1 )*/
 

 

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.