c++ - array pass by value vs an int? -
this question has answer here:
- what array decaying? 7 answers
- simple c++ swap function 3 answers
how come pass value doesnt reset array global while int pass value resets if change in function? example, items_ordered becomes 0 when return though added 1 array doesn't become how started before function called. know if pass items_ordered reference change
#include <iostream> using namespace std; void meal(char menu_1[], int order); int main() { char menu_order[50]; int items_ordered = 0; meal(menu_order, items_ordered); cout<<items_ordered<< menu_order; return 0; } void meal(char menu_order[50],int items_ordered) { cout<< "please enter item order\n"; cin.get(menu_order, 50, '\n'); cin.ignore(100,'\n'); items_ordered += 1; }
Comments
Post a Comment