I was wondering if there is some advantage of using a char-array over a char-pointer? From were I can see char-array are static and in most cases
consumes more memory than pointers.
Why use a char-array?????Code:#include <iostream> using namespace std; int main() { char name[5] = "Eric"; char *pname = "Eric"; cout << "char-arrays name is " << name << endl; cout << "char-pointers name is " << pname << endl << endl; //name = "Alexander"; //Out if bounds pname = "Alexander"; //No problemo cout << "After new assignment..." << endl; cout << "char-arrays name is " << name << endl; cout << "char-pointers name is " << pname << endl << endl; cout << "And now the size of them" << endl; cout << "char-arrays size is " << sizeof(name) << " bytes" <<endl; cout << "char-pointers size is " << sizeof(*pname) << endl << endl; //Don´t really sure which of them to use, but I guessed that it has to be //the object it points to //cout << "char-pointers size is " << sizeof(pname) << endl << endl; return 0; }



LinkBack URL
About LinkBacks


