Home Forums C Programming Calling function with main()

Viewing 3 reply threads
  • Author
    Posts
    • #1881
      JAZYY18
      Participant

      hi
      Here is program which call function without calling main()

      #include
      #include
      #define FIRST   0
      #define SECOND  1
      #define THIRD   2

      file://Variables
      int a,b,c,ch;
      float d;
      file://Function Prototype
      void Read();
      void Operation();
      void Display();
      #pragma startup Read       0 file://First_Priority
      #pragma startup Operation  1 file://Second_Priority
      #pragma exit Display     file://Third_Priority
      void main()
      {
       printf("
      Enter to main() ");
       getch();
       printf("
      Exit From main() ");
       getch();
      }
      void Read()
      {
       clrscr();
       printf("
      Enter the value of a : ");
       scanf("%d",&a);
       printf("
      Enter the value of b : ");
       scanf("%d",&b);
      }
      void Operation()
      {
       printf("
      ArithMetic Operations
      ");
       printf("
      ");
       printf("1  -> Addition
      ");
       printf("2  -> Subtraction
      ");
       printf("3  -> Multiplication
      ");
       printf("
      ");
       scanf("%d",&ch);
       switch(ch)
       {
        case 1:
           c = a+b;
           break;
        case 2:
           c = a-b;
           break;
        case 3:
           c = a*b;
           break;
       }
      }
      void Display()
      {
       switch(ch)
       {
        case 1:
          printf("
      The Result (Addition) : %d",c);
          break;
        case 2:
          printf("
      The Result (Subtraction): %d",c);
          break;
        case 3:
          printf("
      The Result (Multiplication): %d",c);
          break;
        }
        getch();
      }
       
      /*cool program*/

       

    • #3134
      msaqib
      Participant

      spsinghs plz can u give an overview of this program, I mean the flow of the program, So that novice users can understand it.
      Thanks

    • #3135
      JAZYY18
      Participant

      hi
      here is pragma explanation..
      Each implementation of C and C++ supports some features unique to its host machine or operating system. Some programs, for instance, need to exercise precise control over the memory areas where data is placed or to control the way certain functions receive parameters. The #pragma directives offer a way for each compiler to offer machine- and operating system-specific features while retaining overall compatibility with the C and C++ languages. Pragmas are machine- or operating system-specific by definition, and are usually different for every compiler.
      Pragmas can be used in conditional statements, to provide new preprocessor functionality, or to provide implementation-defined information to the compiler

    • #3136
      will
      Participant

      Thanks spsinghs for explanations.

Viewing 3 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.