EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / C program without writting main() function

C program without writting main() function

|

Miscellaneous › Others › C program without writting main() function

  • This topic has 3 replies, 2 voices, and was last updated 13 years, 1 month ago by AJISH ALFRED.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • February 24, 2013 at 5:49 am #2131
    Monika
    Participant

    Hi….

         Can anyone plzzzzz make me understand how the code works of a program without a main() function.

    I am writting a program below, it works correctly and gives the desired output but I am unable to understand its logic. Plzzzzz help me here to get the concept. And one more thing, as I am a BCA pursuing student so which forum should I join???

     

     

    #include<stdio.h>

    #define decode(s,o,l,v,i,n,g)v##s##l##o

    #define start decode(a,n,i,m,a,l,s)

    void start()

    {

         printf(“Hello”);

    }

     

    February 24, 2013 at 10:05 pm #9177
    AJISH ALFRED
    Participant

    Hi Monika,

     

    Interesting question.

    There is actually a main() there in your code.

     

    Try to understand the meaning of the following macros.

     

     

    #define decode(s,o,l,v,i,n,g)v##s##l##o

    A function named ‘decode’ with 1st argument ‘s’, second argument ‘o’, third argument ‘l’ and so on, is defined as nothing but a ‘string’, formed by concatinating the following arguments in the order,

    v – 4th argument

    s – 1st argument

    l – 3rd argument

    0 – 2nd argumnet

     

    Now this function is called by another function named ‘start’ which is defined as below.

     

    #define start decode(a,n,i,m,a,l,s)

    A function named ‘start’ with no arguments, is defined as making a fucntion call to the already defined function ‘decode’ along with passing value to 1st argument as ‘a’, 2nd argument as ‘n’ and so on.

     

    Now the working! On this function call the function ‘decode’ receives the argument values as follows

    No.     argument      value received

    1               s                      a

    2               o                      n

    3               l                       i

    4               v                     m

    5               i                       a

    6               n                      l

    7               g                      s

     

     

    Now what the ‘decode’ function is defined as?

    It forms a string by concatinating the values of arguments in the order v, s, l, o

     

    argument     value     concatenation process

    v                    m               m

    s                     a                ma

    l                      i                mai

    o                    n                main

     

    You see how the main is made??

     

    Simply, the function ‘start’ is defined as making a function call to decode which is alredy defined as generating a string ‘main’ on that function call from start.

    Hence ‘start’ is indeirectly defined as ‘main’

     

    It is like writing the following statement

     

    #define start main

     

    I hope this ‘animal’ has helped you in ‘solving’ your question much better than people from other forums do!!

     

    You can concentrate on forums based on programming questions only. Since your questions will be answered by people who have spend major part of their life in programming, they will consider these kind of questions as silly once and you won’t get an explanation like the one I’ve given you on your question.

    So I suggest you to try the people on other general technical forums like engineers garage’s before bothering experts on programming questions based forums.

     

     

    February 25, 2013 at 2:44 pm #9183
    Monika
    Participant

    Hi Ajish…

        Thank you so much for the explanation.

    February 26, 2013 at 1:37 pm #9186
    AJISH ALFRED
    Participant

    You are welcome.

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • timing delay code statements using Swordfish April 20, 2026
  • S1MJ ? April 20, 2026
  • Bot checks April 19, 2026
  • Getting into an LED bulb April 19, 2026
  • Understanding reversing polarity at astable multivibrator April 19, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise