uint64_t build_table ( int32_t myparameter ) { if ( myparameter == 7 ) { return BOOL_TRUE; } else if (myparameter == 29 ) { return BOOL_FALSE; } else { return 23; } return 5; }
Kalim, You must analyze your statements line by line and must understand the scope of if...else statements.
its too very difficult i try all yesterday but it does not work now.
plz someone give me the code.
If you want a special return value for input value 0, then you need a conditional that matches input value 0.
Right now, you have two (!) different wild-card statements that catch any value not already explicitly tested. Obviously, the first of the two wild-card statements will be the winning one, since the processor will leave the function as soon as it reaches a "return" statement. So having one more "wild card" return statement at the end of the function is irrelevant - the processor can never ever reach that statement.
This should be 100% obvious if you do look at the code I did post. Anything not matching the first "if" will try to match the second "if". And anything that doesn't match that "if" either will then enter the "else" and return.
Most compilers would warn that the last "return" is unreachable, if you just remember to configure your project to compile with all warnings enabled.
now i told to only return BOOL_TRUE or BOOL_FALSE but i need to also return 27, 23 and 5. can i return more values if i make it a class?
uint64_t build_table ( int32_t myparameter ) { if ( myparameter == 7 ) { return BOOL_TRUE; } else if (myparameter == 29 ) { return BOOL_FALSE; } else { return 23; } else if (myparameter != "0") { return 27; } else { return 5; } }
also can you tell me what is different with pass by value and pass by reference cuz i now hear i must return value
and what is difference with argument and parameter
You can return more values if you simply code it properly. If the if/then/else logic escapes you consider a switch/case implementation.
At the moment you pass in a value, and return a value, not sure this situations calls for anything more complex until you grasp the concepts more thoroughly.
Do you understand pointers?
Please find a copy of the K&R C manual and read it.
One if can only have one else.
And anything that doesn't match the if will (!) enter the else.
Your code have an extra else that isn't matched by a previous if.
And you then suddenly compare your int-valued parameter with the address the compiler/linker used to store the text string "0".
A good programming book and some quality time reading it is the best investment - you will just waste time doing trial-by-error programming.
i will try more code but it is very difficult
will you tell me what is the same as parameter and argument?
Why do you want to try more code?
Isn't it better to understand the code instead of doing wild experiments?
This is your last code with extra braces added to show what the compiler will do with the code.
if (myparameter == 7) { return BOOL_TRUE; } else { if (myparameter == 29) { return BOOL_FALSE; } else { return 23; } } else { <=== this else doesn't belong to any if!!! // "0" isn't a number but an address to a text string... if (myparameter != "0") { return 27; } else { return 5; } }
Read books and learn to understand code. Don't guess.
Greeting Kalim Rohgash
Did you get your code fixed. I have a same problem and do not know what to fix.