[X-posted to comp.lang.c and comp.lang.c++]
Post by maverikPost by cnoePost by maverikPost by Joachim SchmitzPost by maverikPost by cnoeSo, what exactly is the difference between those two ?
I'm quite familiar with the arrays and I'm implementing it for matrix
representations.
So, what is a Vector ? how it is different from an Array ?
a vector is a one dimensional matrix
oh no there isn't
Post by maverikWhat do you mean? Is it std::vector?
yes
Post by maverikPost by cnoePost by maverikI know. May be cnoe meand std::vector (from C++)? Just a guess.
yes, ppl it's
std:: vector
let me know that .
I've no idea what that means
Post by maverikI think the difference between the *abstract* definitions of those
terms is a bit ambiguous, so I'm not going to comment on them.
If you are talking about
std::vector<int> a;
vs.
int a[10];
there are big differences between the two.
yes, vector doesn't exist in C
Post by maverikThe latter is a contiguous
chunk of memory of size sizeof(int) * 10 (or, more generally, sizeof
(T) * N, where T is the type of the elements and N is the number of
elements). You can then access a particular element by specifying its
relative position as an integer subscript, or by setting up a pointer
to the array and performing arithmetic on that pointer. This array
can't be resized; once allocated, it remains with the same size for
the rest of its lifetime. In C, the only way to work around this
int* a = malloc(sizeof(int) * 10);
int* new_a = realloc(a, sizeof(int) * 20);
so you *can* resize an array. Or at least treat a resizable
block of memory like an array
Post by maverikstd::vector is a high-level abstraction that provides automatic
resizing and other functionality through methods. Also, as others have
pointed out, std::vector is only available in C++, not in C.
also the memory used for the elements must also be contiguous.
You can also access a particular element by specifying its
relative position as an integer subscript, or by setting up a pointer
to the array and performing arithmetic on that pointer.
Since you specifically said this about arrays but not about
C++ vectors I thought you were implying that this was not true.
--
Nick Keighley
Server rooms should be unfriendly! They should look dangerous,
they should be uncomfortably cold, they should be inexplicably noisy.
If you can arrange for the smell of burning transistors, that's good
too.
If anything, I'd rather see rackmounted servers designed in dark
foreboding
colors with lots of metal spikes sticking out of them.
Mike Sphar (on news//alt.sysadmin.recovery)