Tuesday, July 14, 2009

What are examples of output statements for arrays and pointers in C++?

I am trying to learn pointers and arrays for C++ class. I am using MS Visual Studio 2005. I can initialize, I can set it. But I can't get it to print to the screen. Any beginner help is welcomed!

What are examples of output statements for arrays and pointers in C++?
You had not said whether you want to print address your pointer points to or data placed at this address.





In plain C:


...


int n = 0;


int *p = %26amp;n;


printf( "At address %p we have value %d\n", p, *p );
Reply:#include %26lt;iostream%26gt;


using namespace std;





int main()


{


int arr[5] : {1,5,3,9,4};





cout %26lt;%26lt; arr[4]; //should print "9"


return 0;


}
Reply:use a for loop


like for(int i=0;i%26lt; 100;i++)


cout %26lt;%26lt; a[i] %26lt;%26lt; endl;


No comments:

Post a Comment