This is different question...can anyone tell...we shld get some text as output
hope u can get the question...........

dont use any aruments or anything in or on main()

we shld juzz keep main() function main() { }

dont use C++ or any other..use only C...

and this has solution.....frnds help me..

Dani AI

Generated

asked for output while keeping main() empty and using C only. called it a party trick; linked to an article and mentioned a clever #define hack. Below are practical, accurate options, plus portability and safety notes so the result still helps years later.

One simple, commonly used approach on GCC/Clang is to run a function before main() with the constructor attribute. This is a compiler extension (not standard C) but works on most Unix toolchains and lets you print without touching main():

#include <stdio.h>

void before_main(void) __attribute__((constructor));

void before_main(void) {
    puts("Output produced before main");
}

int main(void) { return 0; }

See the GCC function attributes documentation for details: GCC Common Function Attributes.

Lower-level alternatives include providing your own entry point (_start) and issuing a write syscall directly, or placing code in ELF init sections (.init_array). Those replace or bypass the usual C runtime and are inherently platform-specific; they also make debugging, sanitizers, and static analyzers behave oddly.

Important cautions: the C standard does not define arbitrary code execution before main(); these are platform/compiler behaviors. Calling library functions from constructors is generally fine on modern Linux/glibc toolchains but not guaranteed everywhere. For production code, putting startup work in main() is the portable choice. For experiments or controlled environments, __attribute__((constructor)) is the cleanest way to satisfy requirement while avoiding the unsafe tricks that warned about.

Recommended Answers

All 2 Replies

So are you learning C, or just generally being a pest posting silly party tricks?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.