iOS Hands First day

Source: Internet
Author: User

////main.m//Lessionpointer////Created by Laouhn on 15/7/24.//Copyright (c) 2015 Chi Hai Tao. All rights reserved.//#import<Foundation/Foundation.h>voidJiaohuan (int*a,int*b) {    *a = *a^*b; *b = *a^*b; *a = *a^*b;}intMainintargcConst Char*argv[]) {    //pointer variable: The variable that stores the address    /** * Pointer defines the function of the data type, tells the system what type of pointer//pointer variable is defined, and the function of the data type (take int as an example) 1. Tell the system I am an int type pointer 2. In the pointer The operation is that the number of bytes per offset is int-4 bytes 3. The pointer controls the number of bytes, int controls 4 bytes*/    /** int a = 10; int *p = null;//pointer variable p char *q = NULL;     The data type of the pointer q is: char *;     Usually we call the pointer, is actually the pointer variable, the pointer is stored in the address//pointer variable address of the output printf ("%p\n", p);     The number of bytes that the pointer variable occupies: Only the number of system operating system bits, 32 os 4 bytes, 64-bit operating system 8 bytes printf ("p =%lu\n", sizeof (p));          printf ("q =%lu\n", sizeof (q));     Fetch operator: & p = &a;     printf ("%p\n", p);     printf ("%p\n", &a);                    The value operator *//PRINTF ("%d\n", *p);          The assignment of a pointer variable: The pointer is redirected, which is the process of re-copying the pointer variable.     Pointer operations: Only add and subtract operations.     printf ("%d\n", * (p+1));          printf ("%p\n", p+1);     printf ("q+1 results after output%d\n", * (q + 1)); *///int a = ten;//int *p = &a;//*p = +;//    //*p on the left side of the equals sign is the assignment to the address stored in P, otherwise it is a value operation//    //int *p = NULL; *p is defined as a pointer variable when defined.//printf ("%d\n", a); //Pointers and Arrays    /** * int a[] = {9, 5, 2, 7};          The array name is the first address of the array, but the array name is a constant address printf ("%p\n", a);                    printf ("%p\n", &a[0]);          int *p = A;     printf ("%d\n", *p);          Pointer offset to pointer type about printf ("%d\n", * (P + 1));          printf ("%d\n", p[1]);          printf ("%d\n", * (p + 1 + 1));               printf ("%d\n", * (p + 1 + 1 + 1));     printf ("%d\n", *a);     printf ("%d\n", * (a+1));          printf ("%-----d\n", a[1]);     int b[] = {3, 8, 4, 9};     p = b;//pointer to//a = B;a is a constant, cannot be assigned, and the pointer is a variable that can be redirected (re-assigned).          Array type, does not match pointer type, what is the problem?     int b[] = {256, 5, 2, 7};     int *p = b;     for (int i = 0; i < 4; i++) {printf ("%d", * (P + i));          }//printf ("%d\n", * (q + 1));     Char str[] = "IPhone";     char *p = str;     Output string by pointer printf ("%s\n", p);     Change h to H, directly through the address of the value inside the change is the value operator * (P + 2)-= 32;          printf ("%s\n", p); In this case, Q stores the address of the constant area, and the contents of the constant area are not allowed to be modified. Remember!!???     (Alt shift +k) char *q = "IPhone"; (q + 2) = ' H ';               printf ("Q's address%p\n", q);     Calculates the length of a string by using a pointer.     Char str[] = "IPhone";     int i = 0;     char *p = str;     while (* (P + i)! = 0) {i++;           } printf ("%d", I);*/    //Array of strings//char strarray[][20] = {"IPhone", "IPod", "IPad", "IWatch"}; //printf ("%s\n", strarray[0]); //an array of pointers, which are stored as addresses .//char *str[] = {"IPhone", "IPod", "IPad", "IWatch"};//    //printf ("++++%lu", sizeof (str));//for (int i = 0; i < 4; i++) {//        //printf ("%p", Str[i]);//printf ("%s", Str[i]);//    }//printf ("\ n"); //printf ("%p\n", &str[0]); //char p[] = "DDDDD"; //array of the above pointers, sorted in ascending order//Str[0] Stores the first address of the iphone//Str[1] The first address of the ipod is stored//Str[2] is the ipad's first address .//Str[3] Iwatch's first address is stored .    /** for (int i = 0, i < 4-1; i++) {for (int j = 0; J < 4-1-I; j + +) {if (strcmp (str)     [j],str[j+1]) >0) {//* (P + 2) p[2]//Compare the contents, the position of the address in the array is exchanged char *temp =str[j];     STR[J] = str[j + 1];     Str[j + 1] = temp; }}} for (int i = 0; i < 4; i++) {//printf ("%p", Str[i]); The elements in the output array printf ("%s", Str[i]);//output array element, corresponding to the contents of the address}//string array char str[4][20] = {"IPhone", "IPod", "IPad", "          IWatch "};     An array of pointers that stores the stack space address char *strarray[4] = {str[0], str[1], str[2], str[3]};     for (int i = 0; i < 4;i++) {printf ("%p", Strarray[i]);      } printf ("\ n");    An array of pointers that stores the address of the constant space char *str1[4] = {"IPhone", "IPod", "IPad", "IWatch"};    for (int i = 0; i < 4;i++) {printf ("%p", Str1[i]); }     */    //Pointers and Functions    intA =5; intb =6; Jiaohuan (&a,&b); printf ("a=%d,b=%d", A, b); return 0;}

iOS Hands First day

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.