passing data in C without returning.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dameon99
    New Member
    • Jun 2007
    • 57

    passing data in C without returning.

    Hi all,
    I am passing data into a function in C to be edited but that function already returns some data. I was wondering how i could pass data in to a function so that when it is edited it is chnaged universally?? Ive tried using pass by reference:
    int myFunction(&dat a)
    butthe compiler chucks a wobbly with it. I thought maybe pointers but I need to be explained how to do it.
  • goelvivek
    New Member
    • Dec 2006
    • 26

    #2
    hello friend you cant return more than one value if you use character array otherwise if you want to edit and return more values than use pointer so it goes to memory address and change the value on the address and you do not have to return any thing and you can handle more than one item

    Comment

    • Dameon99
      New Member
      • Jun 2007
      • 57

      #3
      Originally posted by goelvivek
      hello friend you cant return more than one value if you use character array otherwise if you want to edit and return more values than use pointer so it goes to memory address and change the value on the address and you do not have to return any thing and you can handle more than one item
      lol, dw, I am well versed that I cant make multiple returns. could you tell me how to use this pointer and give me an example?

      Comment

      • Dameon99
        New Member
        • Jun 2007
        • 57

        #4
        Thanks Goelvivek. that was everything I needed! :-D

        Comment

        • gsi
          New Member
          • Jul 2007
          • 51

          #5
          Hi,

          Ive tried using pass by reference:
          C uses strictly pass by value. Do some thing like,

          [code=cpp]

          void func(int *a){ // a declared to be a pointer variable.
          *a = 100;
          }

          int main(){
          int a = 10;
          func(&a); // Pass the address of variable
          printf("%d",a); // Prints out 100.
          return 0;
          }
          [/code]

          Thanks,
          gsi.
          Last edited by JosAH; Oct 7 '07, 02:08 PM. Reason: fixed the [code] tags

          Comment

          Working...