Thread: fortran / c++ function arguments

  1. #1

    Cool fortran / c++ function arguments

    Hi there,

    another question, i've to finish a fortran -> c++
    conversion today and i have little programming
    experience in both languages . my question
    about passing arguments is:
    in fortran i can modify a local variable by calling
    a function like this:

    call derivs(xh,yt,dyt)
    call derivs(xh,yt,dym)
    call derivs(xh,yt,dyl)

    in which the last argument is actually the
    most wanted local output (return) variable. (it doesn't
    have to be the same as in the function definition,
    which can look like: subroutine derivs(a,b,c)).

    how can i achieve this in c++? by this i mean
    getting different return names from a
    function call?

    any help is greatly appreciated. o and monster
    thanx for your answer to the last question ...


  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Northern Virginia/Washington DC Metropolitan Area
    void func1()
        int local_var;       // Local integer variable
        local_var = 10;    // Initialize local_var to 10
        local_var = func2();  // local_var is now 20 instead of 10
    int func2()  // func2 returns an integer argument to calling function
        return 20;  // Return the value 20 to the calling function
    Is this what you are talking about or something else perhaps?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    thx! though i think i found what i was looking for:
    i want to perform the same operation on different
    arrays i think i should be working with pointers
    as arguments. after running the code below
    i think i understand how it works.

    i read somewhere that FORTRAN works with
    reference arguments to functions as a default,
    while c++ works with values itself as defaults.

    sorry the question above was a little confusing
    to say the least



    #include <iostream>
    using namespace std;

    void functest(int* a){

    int main () {
    const int r=5;
    int y[r];
    int i=0, j;
    cout << i << "\t" << y[i] << "\n";
    cout << "\n"<< i << "\t" << y[i];
    return 0;


  4. #4
    Registered User
    Join Date
    Oct 2001
    #include <iostream>
    using namespace std;
    void add(int a, int b, int &c);
    int main(void)
       int a = 5;
       int b = 3;
       int c;
       cout << a << "+" << b << "=" << c << endl;
       return 0;
    void add(int a, int b, int &c)
       c = a + b;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Sending multiple arguments to function..
    By Zzaacchh in forum C++ Programming
    Replies: 3
    Last Post: 09-06-2008, 03:20 PM
  4. Arrays as function arguments :(
    By strokebow in forum C Programming
    Replies: 10
    Last Post: 11-18-2006, 03:26 PM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM