fortran / c++ function arguments

This is a discussion on fortran / c++ function arguments within the C++ Programming forums, part of the General Programming Boards category; Hi there, another question, i've to finish a fortran -> c++ conversion today and i have little programming experience in ...

  1. #1
    Martijn
    Guest

    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 ...

    Martijn

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    Code:
    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
    Martijn
    Guest
    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

    Greetz






    ____code_______________________

    #include <iostream>
    using namespace std;

    void functest(int* a){
    a[2]=8;}

    int main () {
    const int r=5;
    int y[r];
    int i=0, j;
    y[0]=0;
    while(i<5){
    cout << i << "\t" << y[i] << "\n";
    i++;
    j=i-1;
    y[i]=y[j]+10;
    };
    functest(y);
    for(i=0;i<5;i++){
    cout << "\n"<< i << "\t" << y[i];
    }
    return 0;
    }

    ______________________________________________

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Code:
    #include <iostream>
    using namespace std;
    
    void add(int a, int b, int &c);
    
    int main(void)
    {
       int a = 5;
       int b = 3;
       int c;
    
       add(a,b,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, 09:18 PM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 04:06 PM
  3. Sending multiple arguments to function..
    By Zzaacchh in forum C++ Programming
    Replies: 3
    Last Post: 09-06-2008, 04: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21