Because when you have a function call like this UCSDStudent( char name[] )
only the adress of the array name
is copied instead of the whole array. It is a C\C++ feature.
Furthermore the name
defined as char name [20]
is not a modifiable lvalue.
Regarding strcpy
: it will bring undefined behaivour as if your source array doesn’t have a NULL character it will copy some trash to this->name
too. You may read more about strcpy
here
Related Contents:
- Accessing an array out of bounds gives no error, why?
- How do I declare a 2d array in C++ using new?
- When a function has a specific-size array parameter, why is it replaced with a pointer?
- Return array in a function
- Passing an array by reference
- Is std::vector so much slower than plain arrays?
- Can someone explain this template code that gives me the size of an array? [duplicate]
- How to emulate C array initialization “int arr[] = { e1, e2, e3, … }” behaviour with std::array?
- How to pass a multidimensional array to a function in C and C++
- May I treat a 2D array as a contiguous 1D array?
- Why are arrays of references illegal?
- c++ array – expression must have a constant value
- Why do C and C++ support memberwise assignment of arrays within structs, but not generally?
- C++ pass an array by reference
- How does this “size of array” template function work? [duplicate]
- How does delete[] know it’s an array?
- Accessing arrays by index[array] in C and C++
- How do I pass a reference to a two-dimensional array to a function?
- Returning arrays from a function in c++
- C/C++ int[] vs int* (pointers vs. array notation). What is the difference?
- How to initialize std::array elegantly if T is not default constructible?
- May I take the address of the one-past-the-end element of an array? [duplicate]
- What is the difference between std::array and std::vector? When do you use one over other? [duplicate]
- too many initializers for ‘int [0]’ c++
- Is there a function to copy an array in C/C++?
- C++ correct way to return pointer to array from function
- What is the difference between Static and Dynamic arrays in C++?
- Why doesn’t C++ support functions returning arrays?
- Comparing arrays for equality in C++
- Pointer to array with const qualifier in C & C++
- Are vectors passed to functions by value or by reference in C++
- Why no variable size array in stack?
- Structure of Arrays vs Array of Structures
- Access array beyond the limit in C and C++ [duplicate]
- Casting pointer to Array (int* to int[2])
- Variable length arrays (VLA) in C and C++
- what is the best modern c++ approach to construct and manipulate a 2d array [closed]
- Remove an array element and shift the remaining ones
- How can I use an array as map value?
- How can I make `new[]` default-initialize the array of primitive types?
- The intersection of two sorted arrays
- C++ overloading array operator
- How do I store arrays in an STL list?
- How to reliably get size of C-style array?
- treating memory returned by operator new(sizeof(T) * N) as an array
- How does *(&arr + 1) – arr give the length in elements of array arr?
- Passing array of structures to function c++
- Pass arrays from C/C++ to Fortran and return a calculated array
- What’s the syntax for declaring an array of function pointers without using a separate typedef?
- General rules of passing/returning reference of array (not pointer) to/from a function?