S
sherifffruitfly
Hi all,
This isn't minimal code, but at least it gives the idea reasonably well
- and yes, I'm a newb
The point of me giving this code is that all three vars look to my eye
as though they're being treated in exactly the same way, so that I end
up confused about why the address-of-char doesn't get returned the way
the other address-of-types do.
(Sorry for bad formatting - I copy/pasted straight out of my IDE...)
Lil insight?
Thanks!
==============
#include <iostream>
using namespace std;
void main()
{
int a = 1;
char b = 'q';
double c = 1.3456;
cout << "Type Size Value Address" << endl;
cout << "int" << " " << sizeof(a) << " " << a << "
" << &a << endl;
cout << "char" << " " << sizeof(b) << " " << b << "
" << &b << endl;
//Why does the above line give gibberish for the address-of-char?
//It's as though it's related to the issue of a c-style string being
an array of char + a null
//on the end, and if you forget to put the null when making a string
"manually", and
//try to print it out, you end up with every memory location being
printed until it
//happens to run across a null. But I really have no idea what the
deal here is.
//Note that I get the expected result if I use the following to begin
with, and put in the obvious
//changes later on:
//char* b = new char('q'); (etc...)
cout << "double" << " " << sizeof(c) << " " << c << " "
<< &c << endl;
return;
}
This isn't minimal code, but at least it gives the idea reasonably well
- and yes, I'm a newb
The point of me giving this code is that all three vars look to my eye
as though they're being treated in exactly the same way, so that I end
up confused about why the address-of-char doesn't get returned the way
the other address-of-types do.
(Sorry for bad formatting - I copy/pasted straight out of my IDE...)
Lil insight?
Thanks!
==============
#include <iostream>
using namespace std;
void main()
{
int a = 1;
char b = 'q';
double c = 1.3456;
cout << "Type Size Value Address" << endl;
cout << "int" << " " << sizeof(a) << " " << a << "
" << &a << endl;
cout << "char" << " " << sizeof(b) << " " << b << "
" << &b << endl;
//Why does the above line give gibberish for the address-of-char?
//It's as though it's related to the issue of a c-style string being
an array of char + a null
//on the end, and if you forget to put the null when making a string
"manually", and
//try to print it out, you end up with every memory location being
printed until it
//happens to run across a null. But I really have no idea what the
deal here is.
//Note that I get the expected result if I use the following to begin
with, and put in the obvious
//changes later on:
//char* b = new char('q'); (etc...)
cout << "double" << " " << sizeof(c) << " " << c << " "
<< &c << endl;
return;
}