A
ali
Hi,
I'm trying to understand the reason for different output on the
following codes
Code1:
#include <iostream.h>
int main()
{
int array[]={2,4,5};
int *pointer =0;
pointer=array;
cout<<pointer<<endl;
return 0;
}
Code2:
#include <iostream.h>
int main()
{
char array[]="words";
char *pointer =0;
pointer=array;
cout<<pointer<<endl;
return 0;
}
Code1 gives me the output as the hexadecimal value of the first
element of the array, which is what i expected the pointer to contain
(memory address), but code2 gives me the output 'words', instead of
the hexadecimal value of the first element of the arrray.
Am i missing something out in understanding the concept?
Will appreciate some help on explaining that.
Thanks,
TJ
I'm trying to understand the reason for different output on the
following codes
Code1:
#include <iostream.h>
int main()
{
int array[]={2,4,5};
int *pointer =0;
pointer=array;
cout<<pointer<<endl;
return 0;
}
Code2:
#include <iostream.h>
int main()
{
char array[]="words";
char *pointer =0;
pointer=array;
cout<<pointer<<endl;
return 0;
}
Code1 gives me the output as the hexadecimal value of the first
element of the array, which is what i expected the pointer to contain
(memory address), but code2 gives me the output 'words', instead of
the hexadecimal value of the first element of the arrray.
Am i missing something out in understanding the concept?
Will appreciate some help on explaining that.
Thanks,
TJ