i commented a line...why does that work, when this also works..Code:#include <iostream> using namespace std; void changevalue(int *value); main() { int value[10]; changevalue(value); for(int x=0; x<10; x++) { cout<<value[x]<<endl;//why does this line work... } return 0; } void changevalue(int *value) { for(int x=0; x<10; x++) { value[x]=x+1; } }why do i need indirection for value (*value) but when i call it as an element from the array, there is no need for the indirection. as in, why does this not work, but the second portion of code does.Code:#include <iostream> using namespace std; void changevalue(int *value); main() { int value[10]; changevalue(value); for(int x=0; x<10; x++) { cout<<*value;//why the need for indirection? } return 0; } void changevalue(int *value) { for(int x=0; x<10; x++) { value[x]=x+1; } }
Thanks.Code:#include <iostream> using namespace std; void changevalue(int *value); main() { int value[10]; changevalue(value); for(int x=0; x<10; x++) { cout<<*value[x]<<endl;//error } return 0; } void changevalue(int *value) { for(int x=0; x<10; x++) { value[x]=x+1; } }



LinkBack URL
About LinkBacks


