Preface:
This is probably gonna be marked as a duplicate, and I understand, but I am asking this, because I feel other answers may not be quite as clear. In fact, the closest answers that I have found that make the most sense to me are this one: from 2015 and this one: from 2013, about return 0;
I have very little programming experience--I messed around with Java several years ago, and kinda figured out what I needed to copy and paste to edit the program I was playing with, and I have written a simple program in python, and I played around with Scratch in School. But, I have finally decided to sit down, learn a language, C, and just roll with it.
So, what I would like to ask, is, am I interpreting this right? because, if so, then it can be said there is, for most intents and purposes, no difference between int main(), with no arguments, and int main(void).
Actual Importance:
To summarise my current understanding:
- If int main()is used, then you should add at the endreturn 0;, to signify the programs termination.
- Though possible, it is improper to use int main()and not usereturn 0;, as many compilers may not recognise this.
- If int main(void)is used, then it is unnecessary to addreturn 0;.
In plain English, would this be said as a good, and/or accurate explanation?
Examples:
/*
 * Program example using scanf, printf, and int main() with no variable
 * This program reads a string from the user
 */
#include <stdio.h>
int main() {
        char name[10];                /* number in square brackets is for max characters in name */
        printf("Enter name: ");
        scanf("%s", name);            /* scanf will read input until it sees blank space, then stop */
        printf("Hello, %s!\n", name);
        return 0;
}
vs.
/*
 * Program example using scanf, printf, and int main(void)
 * This program reads a string from the user
 */
#include <stdio.h>
int main(void) {
        char name[10];                /* number in square brackets is for max characters in name */
        printf("Enter name: ");
        scanf("%s", name);            /* scanf will read input until it sees blank space, then stop */
        printf("Hello, %s!\n", name);
}
 
     
     
     
    