C Program to Display Function without using the Main Function


This is a C program to display function without using the main function.

Problem Description

This program displays function without using the main function.

Problem Solution

1. Use #define macro to rename the main.
2. Print the output and exit.

Program/Source Code

Here is source code of the C Program to display function without using the main function. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C Program to display function without using the Main Function
  3.  */
  4. #include <stdio.h>
  5. #define decode(s,t,u,m,p,e,d) m##s##u##t
  6. #define begin decode(a,n,i,m,a,t,e)
  8. int begin()
  9. {
  10.     printf(" helloworld ");
  11. }
Program Explanation

1. Use #define macro for doing this.
2. #define decode(s,t,u,m,p,e,d) m##s##u##t.
This code says, next time when decode is encountered with 7 parameters, replace it by the concatenation of the 4th,1st,3rd and 2nd argument.
3. #define begin decode(a,n,i,m,a,t,e). In this line the 4th, 1st, 3rd and 2nd argument are m, a, i and n respectively. So the main is replaced by begin.
4. Use function named begin and print the output as ” helloworld ” and exit.

Runtime Test Cases

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics, go to C Programming Examples.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter