码迷,mamicode.com
首页 > 其他好文 > 详细

002 格式化输出

时间:2019-09-07 13:15:03      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:turn   span   字符   ret   格式化   color   style   div   原理   

 

/*
目录:
   一 不同类型用其他类型输出
   二 看原理  
*/

 

 一 不同类型用其他类型输出

int main()
{
    printf("%d\n", c);    // 输出方式: 字符类型 - 整数类型
    printf("%c", 99);       // 输出方式: 整数类型 - 字符类型
    
    return 0;
}


/*
99
c
*/

 

 

二 看原理 
int main()
{
00044290  push        ebp  
00044291  mov         ebp,esp  
00044293  sub         esp,0C0h  
00044299  push        ebx  
0004429A  push        esi  
0004429B  push        edi  
0004429C  lea         edi,[ebp-0C0h]  
000442A2  mov         ecx,30h  
000442A7  mov         eax,0CCCCCCCCh  
000442AC  rep stos    dword ptr es:[edi]  
    printf("%d\n", c);
000442AE  push        63h  
000442B0  push        offset string "%d\n" (046CC0h)  
000442B5  call        _printf (04131Bh)  
000442BA  add         esp,8  
    printf("%c", 99);
000442BD  push        63h  
000442BF  push        offset string "%c" (046B4Ch)  
000442C4  call        _printf (04131Bh)  
000442C9  add         esp,8  

    return 0;
000442CC  xor         eax,eax  
}

 

printf("%d\n", c);
000442AE  push        63h

原理: 编译器对字符类型提取做转换->整数类型



 

002 格式化输出

标签:turn   span   字符   ret   格式化   color   style   div   原理   

原文地址:https://www.cnblogs.com/huafan/p/11479960.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!