B
Bill Reyn
I am a Java programmer, a newbie with c++, struggling a bit...
Why does the code below return the starting address for an integer
array, but for a char array it does not return the starting address,
rather the actual total char array? Where's the address gone for the
char array pointer? It was OK for the int array.
Why the contradiction. What's the logic behind all this? Is it just a
compiler fudge?
#include <iostream>
using namespace std;
int main()
{
char l = 's';
int num[] = {1,2,3,4,5,6,7,8,9,10};
char* ch = {"Ritchie did this"};
cout << " ch is " << ch << " num is " << num << endl ;
return 0;
}
output is:
ch is Ritchie did this num is 0012F77C
Press any key to continue
-----------------------------------
If your interested in Cplusplus its:
void SwapInt( int &nA, int &nB)
{
int nC;
nC = nA;
nA = nB;
nB = nC;
}
Why does the code below return the starting address for an integer
array, but for a char array it does not return the starting address,
rather the actual total char array? Where's the address gone for the
char array pointer? It was OK for the int array.
Why the contradiction. What's the logic behind all this? Is it just a
compiler fudge?
#include <iostream>
using namespace std;
int main()
{
char l = 's';
int num[] = {1,2,3,4,5,6,7,8,9,10};
char* ch = {"Ritchie did this"};
cout << " ch is " << ch << " num is " << num << endl ;
return 0;
}
output is:
ch is Ritchie did this num is 0012F77C
Press any key to continue
-----------------------------------
If your interested in Cplusplus its:
void SwapInt( int &nA, int &nB)
{
int nC;
nC = nA;
nA = nB;
nB = nC;
}