指向指针的指针剖析

  1 #include <stdio.h>
  2 #include <string.h>
  3 
  4 void swap_str(char **a,char **b) ;
  5 int main()
  6 {
  7  
  8     char * p1= "apple" ,* p2="orange" ;
  9     
 10 
 11    printf("before swap pointer fruits are \n%s %s\n\n",p1,p2);
 12    swap_str(&p1,&p2);
 13    printf("after swap pointer fruits are \n%s %s\n",p1,p2);
 14 }  
 15 
 16 
 17 void swap_str(char **a,char **b)
 18 {
 19    char * t ;
 20    t = *a;
 21    *a = *b ;
 22    *b = t; 
 23    
 24 };    


编译执行结果
[root@ACA60105 c]# gcc -g ptp.c 
[root@ACA60105 c]# ./a.out 
before swap pointer fruits are 
apple orange


after swap pointer fruits are 
orange apple






void swap_str(char **a,char **b)                                        
{                                                                       
  400676: 55                   push   rbp                             
  400677: 48 89 e5             mov    rbp,rsp                         
  40067a: 48 89 7d e8           mov    QWORD PTR [rbp-0x18],rdi        
  40067e: 48 89 75 e0           mov    QWORD PTR [rbp-0x20],rsi        
   char * t ;                                                           
   t = *a;                                                              
  400682: 48 8b 45 e8           mov    rax,QWORD PTR [rbp-0x18]        
  400686: 48 8b 00             mov    rax,QWORD PTR [rax]             
  400689: 48 89 45 f8           mov    QWORD PTR [rbp-0x8],rax         
   *a = *b ;                                                            
  40068d: 48 8b 45 e0           mov    rax,QWORD PTR [rbp-0x20]        
  400691: 48 8b 10             mov    rdx,QWORD PTR [rax]             
  400694: 48 8b 45 e8           mov    rax,QWORD PTR [rbp-0x18]        
  400698: 48 89 10             mov    QWORD PTR [rax],rdx             
   *b = t;                                                              
  40069b: 48 8b 45 e0           mov    rax,QWORD PTR [rbp-0x20]        
  40069f: 48 8b 55 f8           mov    rdx,QWORD PTR [rbp-0x8]         
  4006a3: 48 89 10             mov    QWORD PTR [rax],rdx             
                                                                        
};    

猜你喜欢

转载自blog.csdn.net/skillfulit/article/details/78445960