Results 1 to 2 of 2

Thread: How to call a function in the "main" function

  1. #1
    Join Date
    Sep 2010
    Posts
    11

    How to call a function in the "main" function

    How do I call a function in the "main" function??
    I know the format is: type name(parameter1, parameter, 2...) { statements }


    For example this function writen below... how would I call it in the main function?? What would it look like? Help



    #include<stdio.h>

    int main()
    {

    int i;

    //A-Z
    for (i='A'; i<='Z'; i++)
    {
    printf("%c\t", i);
    }
    }

  2. #2
    Join Date
    Apr 2009
    Posts
    89

    Re: How to call a function in the "main" function

    I am providing you with an example in C++. I am sure that you will get some ideas about calling the "main" function :
    Code:
    // function example
    #include <iostream>
    using namespace std;
    
    int addition (int a, int b)
    {
      int x;
      x=a+b;
      return (x);
    }
    
    int main ()
    {
      int y;
      y = addition (2,6);
      cout << "The result is " << y;
      return 0;
    }
    The parameters and arguments have a clear correspondence. Within the main function we called to addition passing two values: 2 and 6, that correspond to the int a and int b parameters declared for function addition. At the point at which the function is called from within main, the control is lost by main and passed to function addition. The value of both arguments passed in the call (2 and 6) are copied to the local variables int a and int b within the function. Function addition declares another local variable (int x), and by means of the expression x=a+b, it assigns to x the result of a plus b. Because the actual parameters passed for a and b are 2 and 6 respectively, the result is 8.

Similar Threads

  1. Adding "Send to OneNote" function in MS Word 2010 .
    By Harri.Son in forum Windows Software
    Replies: 2
    Last Post: 09-04-2012, 08:12 PM
  2. Replies: 1
    Last Post: 15-02-2012, 12:07 AM
  3. Replies: 8
    Last Post: 07-12-2011, 02:14 PM
  4. Replies: 4
    Last Post: 12-07-2010, 10:38 PM
  5. How to disable "The User Account auto lock function"?
    By gajaratna in forum Small Business Server
    Replies: 3
    Last Post: 05-04-2008, 04:46 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,457,942.89476 seconds with 17 queries