return 唔會變任何野,只係會將function入面個數扔返出來
而void 係無野扔出來
例如- int getAmount(int amount)
- {
- return 0;
- }
- void getAmountVoid(int amount)
- {
- }
- int main(int argc, char **argv)
- {
- int amount = 10;
- //amount is 10
- amount = 5;
- amount = setAmount(amount);
- //amount is 0 , assigned value from the funcion
- //Cannot compile if the line below is uncommented, because compiler cannot get value from void function
- //amount = getAmountVoid(amount)
- }
複製代碼 |