I'm studying Learn to Code with C by Simon Long. https://www.raspberrypi.org/magpi-issues/Essentials_C_v1.pdf on page 20 there is this simple program:
#include <stdio.h>
void main (void)
{
int a = 0;
while (a < 5)
{
printf ("a is equal to %d\n", a);
a++;
}
printf ("a is equal to %d and I've finished\n", a);
}
But when I compile this I get this compiler error:
while-loop.c:3:1: warning: return type of 'main' is not 'int'
[-Wmain-return-type]
void main(void)
^
while-loop.c:3:1: note: change return type to 'int'
void main(void)
^~~~
int
1 warning generated.
Why is this? It seems that the author's compiler does not give error for this. Why the discrepancy?
When I change
void main (void)
to
int main (void)
it compiles fine.