c语言float变量和字符串转换占内存大小问题

2019-03-24 16:59发布

本帖最后由 dinghao1 于 2018-7-26 10:47 编辑

1.不进行字符串转换,程序大小48B
  1. #include<reg52.h>
  2. #include<stdio.h>
  3. #define uchar unsigned char
  4.         
  5. float fengsu;
  6. long  guang;
  7. uchar str[10];
  8.         void display1()
  9.     {
  10.         guang=60000;
  11.                         //  sprintf(str,"%5ld",guang);
  12.                         }
  13.         void display2()
  14.     {
  15.                         fengsu=12.34;
  16.                 //        sprintf(str,"%5.2f",fengsu);
  17.                 }
  18. void main()
  19. {
  20.         while(1)
  21.         {        
  22.     display1();
  23.                 display2();
  24.         }
  25. }
复制代码


此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
13条回答
dinghao1
2019-03-25 05:23
4,删掉float变量,只有长整数转换,程序大小1110B
#include<reg52.h>
#include<stdio.h>
#define uchar unsigned char
       
float fengsu;
long  guang;
uchar str[10];
        void display1()
    {
        guang=60000;
                          sprintf(str,"%5ld",guang);
                        }
        void display2()
    {
                        //fengsu=12.34;
                        //sprintf(str,"%5.2f",fengsu);
                }
void main()
{
        while(1)
        {       
    display1();
                display2();
        }
}

一周热门 更多>