Thread: int question

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    12

    int question

    somewhere in the tutioral for this site i think the function page i saw a thing that says

    int mult(int x, int y);

    i was wondering why they used this? isnt it the same as doing

    int x;
    int y;


  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    29

    Post Mult function

    I'll try to clear things up..

    What I think you are referring to there, is a function prototype. I think that one (if I remember the tutorials correctly) is a function that multiplies two numbers.

    Although it looks somewhat like a variable declaration, its actually a prototype for a function (function is kinda like a little snippet of code that can be called)

    The reason that is used, is because that function takes two arguments (x, y) and multiplies them.

    I'm not gonna go into all the details of the uses of functions, and how they work, just cause.. well, theres already a tutorial on that.

    I hope that helped somewhat
    Last edited by SushiFugu; 12-09-2001 at 03:16 AM.

  3. #3
    int mult(int x, int y);

    you use this if you want to pass some numbers to the function.
    take the multiply example. lets say you want to multiply to numbers entered by the user. then you want to use those numbers in the function. so you need to give them to the function.
    Code:
    #include <stdio.h>
    
    multiply(int x, int y);//this is the function prototype
    
    int main(void)
    {
    int a,b;
    scanf("%d",&a);
    scanf("%d",&b);
    multiply(a,b);//Call the function
    return 0;
    }
    
    multiply(int x, int y)
    {//x contains the value of a and y contains the value of b
    int result;
    result=x*y;
    printf("the result is %d",result);
    return;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  3. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM