How do you change the value of a variable using a function?

This is a discussion on How do you change the value of a variable using a function? within the C++ Programming forums, part of the General Programming Boards category; So how do you do that, like in the function GEtBuffer()?...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    151

    How do you change the value of a variable using a function?

    So how do you do that, like in the function GEtBuffer()?
    Last edited by bijan311; 02-28-2011 at 06:48 AM.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,791
    Be more specific. What variable and how do we change it (that is, in what way do we want to modify it)?
    Is it a global variable, a local variable, a static variable? Is it a variable that we return? Is it a parameter?
    Examples? Code? Something to show what you mean?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    151
    Well this is what I mean

    Code:
    //At the beggining pBackBuffer is NULL
    ID3D10Texture2d pBackBuffer = NULL;
    GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer);
    //At the end pBackBuffer has a value

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,791
    Right, well there are two ways, of which I will demonstrate only one:
    Code:
    void foo(int& v) { v = 10; }
    // Call as
    int x;
    foo(x);
    // x is now 10.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438
    //At the beggining pBackBuffer is NULL
    ID3D10Texture2d pBackBuffer = NULL;
    GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer);
    //At the end pBackBuffer has a value
    I am not sure from this or some of your other posts just how much experience you have in programming? It seems you may be 'diving in' and taking something very complicated on from the getGo?

    One would assume that the GetBuffer returns a texture surface that uses pointers internally..? or or some similar operation, the programmer attempts to NULL the type before using it.
    And if you actually mean 'how does a function change a value' , as in Elysia's example...well you need to study a little before hoping to create any games...
    Last edited by rogster001; 02-28-2011 at 07:03 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointers
    By MrMatt027 in forum C++ Programming
    Replies: 14
    Last Post: 12-10-2010, 03:32 PM
  2. Change function
    By cody.carter in forum C Programming
    Replies: 19
    Last Post: 05-17-2010, 11:19 AM
  3. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  4. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 07:55 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM

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