Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Functions

Functions

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bhangie
    wrote on last edited by
    #1

    Is there something wrong with this code? void Calculate(const int &a, float *b, int &c); //? int a; //can i initialize a float b; int c; float d = 20.4; Calculate(a,b,c); //function call void Calculate(const int &a, float *b, int &c) { //Code // }; lets say a is 4, b is 0.0 and c is 5. a is supposed to stay 4, b is supposed to be 0.25 and c 24.4 when the function returns. Can someone correct please oh and its not home work or an assignment or something Thanks bhangie :-D

    L L 2 Replies Last reply
    0
    • B bhangie

      Is there something wrong with this code? void Calculate(const int &a, float *b, int &c); //? int a; //can i initialize a float b; int c; float d = 20.4; Calculate(a,b,c); //function call void Calculate(const int &a, float *b, int &c) { //Code // }; lets say a is 4, b is 0.0 and c is 5. a is supposed to stay 4, b is supposed to be 0.25 and c 24.4 when the function returns. Can someone correct please oh and its not home work or an assignment or something Thanks bhangie :-D

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      In what way are the parameters being calculated? There must be some sense of the "Calculate" function :confused: What do you want to achieve? regards

      1 Reply Last reply
      0
      • B bhangie

        Is there something wrong with this code? void Calculate(const int &a, float *b, int &c); //? int a; //can i initialize a float b; int c; float d = 20.4; Calculate(a,b,c); //function call void Calculate(const int &a, float *b, int &c) { //Code // }; lets say a is 4, b is 0.0 and c is 5. a is supposed to stay 4, b is supposed to be 0.25 and c 24.4 when the function returns. Can someone correct please oh and its not home work or an assignment or something Thanks bhangie :-D

        L Offline
        L Offline
        Larry J Siddens
        wrote on last edited by
        #3

        Some comments: If you don't want a to change a variable, don't pass a reference to it. You can do something like this: void Calculate( const int a, int c, float* f ); Here I'm not passing any references and you cannot change 'a' within Calculate. I can change the value of 'c' within the function, except the variable will retain its original value upon return. Now you maybe asking why I changed the parameter order. Mainly preferrence. I like to have the same types grouped together. Yes, you can initialize 'a' just like you did with float. The variable 'a' at the point you placed it is not a constant value. If you have anymore questions, just ask. Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups