943,657 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4541
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Apr 13th, 2008
0

Program without main()

Expand Post »
Is it possible to print anything on screen in C or C++ without using main().If yes please explain how?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rukunaditya is offline Offline
3 posts
since Apr 2008
Apr 13th, 2008
0

Re: Program without main()

main() is the start of any C++ application, why do you need to do it without it ?
Reputation Points: 1429
Solved Threads: 129
Posting Virtuoso
William Hemsworth is offline Offline
1,542 posts
since Mar 2008
Apr 13th, 2008
0

Re: Program without main()

main() is the start of any C++ application, why do you need to do it without it ?
In one of the programming competetions in my college we were asked to do this.
Although none was successful
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rukunaditya is offline Offline
3 posts
since Apr 2008
Apr 13th, 2008
0

Re: Program without main()

Because it's a frequent teaser question which some tutors think are useful in some way.
Like for example printing without using a ; or making the program print it's source code or some other dumb trick.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Apr 13th, 2008
0

Re: Program without main()

>>Is it possible to print anything on screen in C or C++ without using main().

Yes -- write a MS-Windows win32 api program which uses WinMain() instead of main(). Or use VC++ 2008 and it will generate a console program that starts with _tmain().
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,949 posts
since Aug 2005
Apr 14th, 2008
0

Re: Program without main()

Thanks very much for your reply.But please I need some more help or atleast some hints as I dont know how to create a MS-Windows win32 api program which uses WinMain() instead of main(). I am new at programming . So please help
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rukunaditya is offline Offline
3 posts
since Apr 2008
Apr 14th, 2008
1

Re: Program without main()

>So please help
Try searching for WinMain on www.google.com. Seriously, it's not that hard to do a little bit of research and come up with something. We tend not to take kindly to willfully clueless people.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Apr 14th, 2008
0

Re: Program without main()

Every ISO standard C/C++ program must have a main(). Windows, other graphic environments, and many embedded systems have a non-standard environment and may not need a main().

So, the answer is: in ISO Standard C/C++, you cannot print anything without having a main() function. If you are talking about a non-standard environment, then the answer is it depends on the environment.
Reputation Points: 18
Solved Threads: 2
Newbie Poster
eager is offline Offline
12 posts
since Jan 2008
Apr 14th, 2008
1

Re: Program without main()

>So, the answer is: in ISO Standard C/C++, you cannot
>print anything without having a main() function.
Unless you're on a freestanding implementation.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
May 26th, 2009
-3

Re: Program without main()

Ok the question asked is never print anything without main() function. The question asked is without anything in main function and it is possible(I know it because i myself have asked this question many times). You can do just about anything without anything inside main() function. The answer is C++ -> class -> global object. Try it and you'll see.
Last edited by abhishekp; May 26th, 2009 at 11:35 am.
Reputation Points: 5
Solved Threads: 0
Newbie Poster
abhishekp is offline Offline
3 posts
since May 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C++ Forum Timeline: array to file
Next Thread in C++ Forum Timeline: Messing up stringstream





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC