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