main.c//C language-pointer////Created by CGQ on 15/4/9.//Copyright (c) 2015 CGQ. All rights reserved.//#include <stdio.h>//Direct reference to void Test () {//through the variable name A to find the address in memory, and then put 10 in 2 in the form of variable a storage control int A; A = 10; Variable address store content//A-ffc1 0000 1010}//Indirect reference void Test2 () {///to store the address of variable A in another variable, and then through variable b The value of the variable A is indirectly read and written by the reference variable A, char A; Char *b; Here the *b just declares that this is a pointer,//Let pointer variable b point to variable a b = &a; *b = 10;//here *b represents access to the storage space stored in B//variable address stored content//a ffc1 0000 1010 (*B)//b FFC2 ffc1 printf ("a=%d\n", a); A = 11; printf ("A =%d\n after assignment", *b); The *b represents the value stored by the variable a}//the pointer is using void swap (int *a1,int *a2)//By value passing and by reference, passing by value does not modify the size of the original value {//Interchange A1 and A2 value int temp; temp = *A1; *A1 = *A2; *a2= temp;} The addition and subtraction operation results of A and B are also obtained, similar to outvoid jiaandjian (int a,int b,int *sum,int *minus) {*sum=a+b; *minus = a-B;} int main (int argc, const char * argv[]) {//Insert code here ... int a = 10; int B = 20; SWAP (&A,&B); printf ("a=%d\nb=%d\n", A, b); int sum; int minus; Jiaandjian (A,b,&sum,&minus); printf ("a+b=%d\na-b=%d\n", Sum,minus); return 0;}
Ios-c Language Exercises 02