0

If I want to add two numbers and print the output on LCD

char answer[8];
float a=5.1,b=3.2,c;
c=a+b;
 dtostrf(c,8,3,answer);//convert float to ASCII to print it on LCD
for(i=0;i<8;i++) Lcd8_Write_Char(answer[i]);

What is the required memory space to execute this program?

  • 2
    You can't execute that program. It's incomplete. Also it's not easy to second guess the optimizer in the compiler. All I can say is "at least 8 plus whatever i needs and maybe a b and c if they don't get optimized out". So between 8 and 24 bytes plus anything else the rest of the program will need. – Majenko Sep 17 at 10:14
  • You can easily find out the size of a program and the needed RAM, by writing a full program (with void setup() and void loop()) and compile it in the Arduino IDE. It will tell you, what you want to know – chrisl Sep 17 at 11:12
  • @chrisl afaik local variables and stack size are not taken into account while compiling, so one needs to use the SRAM size mentioned by the compiler + the maximum amount / deepest stack flow arguments usage + local variables. – Michel Keijzers Sep 17 at 11:34
  • You can use the utility freeRAM playground.arduino.cc/Code/AvailableMemory to check what the compilation can't tell you. Besides, your variable answeris too small by 1 (the trailing \0 ) – DataFiddler Sep 17 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.