Even the second (most recent) edition of Kernigan and Ritchie’s book C Programming Language was written and published before C was standardized for the first time. After the release of the first standard of the language, the text of the book was corrected in hindsight, but most of the code examples used in the book did not affect these edits. Since then, the language standard has changed, but the book, of course, has not been brought into line with the new C standards. For this reason, this book today represents only mainly historical / entertainment value. And code samples in it and earlier were low-quality / obsolete.
As for the example you cited, if you close your eyes to the numerous stylistic flaws, it is obviously only the declaration of the main function that is erroneous. It relies on two [related] properties of the standard C language: the "implicit int" rule and the "empty decl-specifier-seq" rule. Namely, in standard C, ads of the form were allowed.
a = 42; /* Пустая decl-specifier-seq */ foo(); /* Пустая decl-specifier-seq */ main(); /* Пустая decl-specifier-seq */
They are, however, prohibited in the standard C language, starting from the very first of its standard. The first standard of C, adopted in 1989 (the so-called C89 / 90, aka "ANSI C") retained the rule of "implicit int", but canceled the possibility of using "empty decl-specifier-seq", which made the above-mentioned declarations illegal . In C89 / 90 you can declare, for example,
const a = 42; /* Непустая decl-specifier-seq, но подразумевается неявный `int` */ static foo(); /* Непустая decl-specifier-seq, но подразумевается неявный `int` */ extern main(); /* Непустая decl-specifier-seq, но подразумевается неявный `int` */
but by no means just foo() , main() or a . The modern language C (starting with C99) no longer supports the rule of "implicit int", i.e. In the modern C type in the ad, you must always indicate clearly
const int a = 42; static int foo(); int main();
You may also notice that in the C language it is not recommended to use function declarations with empty brackets () . Such ads are obsolete (obsolescent) from the very first language standard, although no one has yet dared to ban them completely. Functions without parameters in C should be declared as (void) , and not as () .
And you can also notice that the absence of an explicit return in the main function in C89 / 90 leads to the fact that the value returned by the main function is not defined. Only starting from C99, the completion of main by the last closing parenthesis implies an implicit return 0; .
argcandargv. Indicate which error appears during compilation. - isnullxbhmain()function has no arguments. Your arguments are just fine. - AnT