This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

printf

Hi,

I am trying to run my first C program on Keil...it works perfectly until I insert a printf statement...am i missing something?

#include <reg52.h>
#include <stdio.h>

void main(void)
{
        unsigned int i;

        unsigned int ans = 0;

        for (i =0; i< 5; i++)
        {
                ans += 2;
        }

        printf("The answer is: " + ans);
}

Parents
  • The last instruction does not do anything - you are never using ans before leaving main() so what do you expect the compiler to do?

    Another thing: You do not have a command line to return to, so do not write a main() that drops you out into the unknown.

    Add an infinite loop at the end of main.

Reply
  • The last instruction does not do anything - you are never using ans before leaving main() so what do you expect the compiler to do?

    Another thing: You do not have a command line to return to, so do not write a main() that drops you out into the unknown.

    Add an infinite loop at the end of main.

Children
No data