Write a simple C/C++ program which defines an array of five elements, then using pointer to display the addresses of all elements of the array.
Write a simple C/C++ program which defines an array of five elements, then using pointer to display the addres
#include %26lt;iostream%26gt;
using namespace std;
int main()
{
int array[5];
int* pointer = NULL;
for(int i = 0; i %26lt; 5; i++)
{
pointer = %26amp;array[i];
cout %26lt;%26lt; "The address of element (" %26lt;%26lt; i + 1 %26lt;%26lt; ") is: ";
cout %26lt;%26lt; %26amp;(*pointer);
}
return 0;
}
// you can also do it without using a pointer as follows:
for(int i = 0; i %26lt; 5; i++)
{
cout %26lt;%26lt; "The address of element (" %26lt;%26lt; i + 1 %26lt;%26lt; ") is: ";
cout %26lt;%26lt; %26amp;array[i];
}
Reply://C//or//C++
-------------------------------
Start
Define: /Array
Elements: /5
Now use:
What?
pointer to address the F* display
what for?
elements of the display?
how many?
5!!!
------------------------------
end
Reply:Any other help me to solve that Question
Reply:/* Tolga's C code */
#include %26lt;stdio.h%26gt;
int main(){
int i=0, arr[5];
for(;i%26lt;5;i++)
printf("Address of the element #%d is %p\n",i,(arr+i));
return 0;}
Reply:dude, that's not even a program. that's like 5 lines of code, if even.
Reply:#include%26lt;iostream.h%26gt;
#include%26lt;stdlib.h%26gt;
int main(){
int *p;
int a[5] = {1,2,3,4,5};
p = a; //simple assignment
for(int i = 0;i%26lt;5;i++)
cout%26lt;%26lt;(p+i);
return 0;
}
Reply:Do your own homework
Reply:Why dont you try your own Mind to Answer your Assignments, you are just sitting in your Campus to ask people to do Assignments for you, hmmmm
Very Bad Hafsa, Very Bad
Reply:/*-------hi dude: try this :its 100% right---------*/
/*-------it really takes something to learn pointers in c---*/
#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
void main()
{
int a[5] = {1,2,3,4,5};
int *i;
for( i = 0; i%26lt;=4; i++)
{
printf("\t%d",*(a+i));
}
getch();
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment