Dev said:
I had faced this objective in one of my aptitude exams, that
"What could be the smallest "C" program?
And, as we know, smallest program means, it should execute
single statement, I wrote ";" (Semicolon), so, program output will
display blank screen.
A lone semicolon is not a valid C program. It can be a null
statement, but only if it appears inside a function definition
(statements cannot appear outside functions). A lone semicolon is
*not* a null declaration (there's no such thing), though some
compilers may allow it.
An empty file is a valid C source file, but it's not a program unless
it includes a definition of main().
A freestanding implementation may define a startup function other than
main. So this:
m(){}
is a valid C program *if* the implementation documents "m" as the name
of the startup function. (As far as I know, there are no such
implementations. My unsupported hunch is that all existing compilers
that define an startup function other than "main" give it a name
that's at least 4 characters long.)
Then again, a conforming C implementation is allowed to provide
extensions as long as they don't alter the behavior of any strictly
conforming program (C99 4p6), and a "conforming program" is one that
is acceptable to a conforming implementation (C99 4p7). So *if* an
implementation provided an extension allowing an empty file to be
equivalent to, say, "int main(void){return 0;}", then an empty source
file would be a "conforming program". (The category of "conforming
program" really isn't particularly useful; it was included in the
standard for political reasons.)
If we wanted to get *really* silly about this, we could define a
mechanism for creating files with negative sizes. For example, a file
with size -100 would become an empty file if you append 100 bytes of
data to it. And as long as we allow this, we might as well implement
files with transfinite negative sizes (along with a C implementation
with an extension that supports such a file). Given these
assumptions, since there is no largest transfinite number, there is no
smallest C program (the same is true if we merely allow finite
negative sizes. And the entire question vanishes in a puff of logic.