Exforsys
+ Reply to Thread
Results 1 to 7 of 7

without main function how can we run c program

This is a discussion on without main function how can we run c program within the C and C++ forums, part of the Programming Talk category; Hi How can we run a " C Langauge program without writing the main function It is possible to do ...

  1. #1
    Dharmesh rathod is offline Junior Member Array
    Join Date
    Feb 2007
    Answers
    2

    without main function how can we run c program

    Hi

    How can we run a " C Langauge program without writing the main function

    It is possible to do it. but can anyone explain this with an example?


  2. #2
    Adrian is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    124
    When a C program is executed the main() is the function called by the run-time environment. But it is possible to write C program without main() function with some trick. I have not done this but will make a try and let you know. Nice question posted which triggered me to try this out.


  3. #3
    shrikant telkar is offline Junior Member Array
    Join Date
    Mar 2007
    Answers
    5

    shri code

    Quote Originally Posted by Dharmesh rathod View Post
    Hi

    How can we run a " C Langauge program without writing the main function

    It is possible to do it. but can anyone explain this with an example?
    thank you. ..........................................................


  4. #4
    easysameer is offline Junior Member Array
    Join Date
    Jul 2008
    Answers
    1

    Smile without main function how can we run c program

    #include<stdio.h>
    #define decode(s,t,u,m,p,e,d) m##s##u##t
    #define begin decode(a,n,i,m,a,t,e)

    int begin()
    {
    printf(" hello ");
    }


  5. #5
    Skunk is offline Junior Member Array
    Join Date
    Jul 2008
    Answers
    1
    Quote Originally Posted by easysameer View Post
    Code:
    #include<stdio.h>
    #define decode(s,t,u,m,p,e,d) m##s##u##t
    #define begin decode(a,n,i,m,a,t,e)
    
    int begin()
    {
    printf(" hello ");
    }
    I disagree - clever though.

    That's still has a main function. If you trace through what the #define's are doing it's just changing "begin()" to "main()". The compiler still sees and compiles "main()".

    It sounded like Dharmesh rathod wanted no main function whatsoever rather than obfuscated code.


  6. #6
    pratap kumar is offline Junior Member Array
    Join Date
    Aug 2008
    Answers
    2

    ans

    Quote Originally Posted by Dharmesh rathod View Post
    Hi

    How can we run a " C Langauge program without writing the main function

    It is possible to do it. but can anyone explain this with an example?

    a program must have a main function (compulsory) without main it is impossible


  7. #7
    zephyr's Avatar
    zephyr is offline Member Array
    Join Date
    Dec 2007
    Answers
    31
    As I know its not possible to run a program without the main function.


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...