Alright... the * attached to the pointer means the contents of whatever it is pointing to right? and & means the address of... so why does this code work...
if the * means the contents of, why couldn't this work, for example:Code:#include <iostream> double result(int * pointer, int counter); main() { int * pointer, counter; std::cout<<"How many items will you be entering?\n"; std::cin>>counter; pointer=new int[counter]; for(int x=0; x<counter; x++) { std::cout<<"Enter value "<<x+1<<": "; std::cin>>pointer[x]; std::cout<<std::endl; } std::cout<<"The average of the numbers entered is: "<<result(pointer, counter)<<std::endl; delete [] pointer; return 0; } double result(int * pointer, int counter) { double total=0; for(int x=0; x<counter; x++) { total+=pointer[x]; } return total/counter; }
now i know that doesn't work. and i understand it doesn't work...but when do you use the * and when do you leave it blank, as far as pointers go? Any global truths?Code:total+=pointer[x]*;



LinkBack URL
About LinkBacks


