C-language string pointers

Source: Internet
Author: User

Recently looking at C language, in the pointer this piece has encountered the trouble, especially the string pointer this piece, simple record under.

string pointers

1 voidMain ()2 {3     Char*p ="tasklist";//pointer, string pointer4printf"%d",sizeof(P));5printf"\n%d",sizeof("tasklist"));//9 characters tasklist6     //p Stores the first address of the constant string "tasklist", which is the address of the T character7     //*p = ' 1 '//cannot assign a value, Tasklist is a pointer, the pointer is a constant cannot be assigned. 8 9printf"\n%c", *p);//TTenprintf"\n%c", * (p+1));//a One  A GetChar (); -}

Array of string pointers

1 //array of string pointers2 voidmain2 ()3 {4     //pointer array p Stores elements that are pointer types, that is, top,ll,ls are pointer types (constants cannot be assigned values)5     Char*p[] = {"Top","ll","ls"};6     intL =sizeof(p)/sizeof(Char*);7     //printf ("%d", sizeof (p)/sizeof (char *));//How many elements of an array8     inti =0;9 Ten      for(; i < L; i++) { One         //I=1 For example, P[i] is the first address of top pointing to top. That is, the address of the T character Aprintf"%c\n", * (P[i]));//Print out character T -printf"%x,%s\n", P[i],p[i]); -     } the  -System"Pause"); -  -}

C-language string pointers

Related Article

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.