Discussion:
Array vs Vector
(too old to reply)
cnoe
2008-12-04 09:31:51 UTC
Permalink
So, 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 ?


Thnx
maverik
2008-12-04 10:26:39 UTC
Permalink
Post by cnoe
So, 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 ?
There is vector in C language. What do you mean? Is it std::vector?
Joachim Schmitz
2008-12-04 10:30:20 UTC
Permalink
Post by maverik
Post by cnoe
So, 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 ?
There is vector in C language. What do you mean? Is it std::vector?
Which is C++, not C

Bye, Jojo
maverik
2008-12-04 10:36:45 UTC
Permalink
Post by Joachim Schmitz
Post by maverik
Post by cnoe
So, 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 ?
There is vector in C language. What do you mean? Is it std::vector?
Which is C++, not C
I know. May be cnoe meand std::vector (from C++)? Just a guess.
cnoe
2008-12-04 10:52:18 UTC
Permalink
Post by maverik
Post by Joachim Schmitz
Post by maverik
Post by cnoe
So, 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 ?
There is vector in C language. What do you mean? Is it std::vector?
Which is C++, not C
I know. May be cnoe meand std::vector (from C++)? Just a guess.
yes, ppl it's
std:: vector

let me know that .

Thnx
Joachim Schmitz
2008-12-04 11:02:28 UTC
Permalink
Post by cnoe
Post by maverik
Post by Joachim Schmitz
Post by maverik
Post by cnoe
So, 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 ?
There is vector in C language. What do you mean? Is it std::vector?
Which is C++, not C
I know. May be cnoe meand std::vector (from C++)? Just a guess.
yes, ppl it's
std:: vector
As said: this is C++, so you should ask about it in comp.lang.c++, not here

Bye, Jojo
Post by cnoe
let me know that .
Thnx
Martin Ambuhl
2008-12-04 11:03:04 UTC
Permalink
Post by cnoe
yes, ppl it's
^^^
A careful writer would write "people".
A programmer who is not a careful writer is a poor programmer.
Post by cnoe
std:: vector
"std::vector" is a syntax error in C.
If that construct appears in the non-C language you are using
then you should post to a newsgroup for that language.
It is oxymoronic that a programmer does not know what computer
language he is using.
Post by cnoe
let me know that .
Thnx
A careful writer would write "Thanks".
A programmer who is not a careful writer is a poor programmer.

You will find it advantageous to save the baby talk for comic book
conventions.
James Harris
2008-12-04 11:22:54 UTC
Permalink
Post by Martin Ambuhl
Post by cnoe
yes, ppl it's
^^^
A careful writer would write "people".
...
Post by Martin Ambuhl
Post by cnoe
Thnx
A careful writer would write "Thanks".
A programmer who is not a careful writer is a poor programmer.
You will find it advantageous to save the baby talk for comic book
conventions.
Too many people pick up vocabulary from SMS text messaging. Maybe they
use their thumbs on qwerty keyboards too...?

IMHO it's a good point you raised with the OP. Folk who's first
language is not English but who participate in Usenet discussion have
a hard enough job to learn the language anyway. Posting messages in a
pidgin form just makes their work - and that of others - harder.

Maybe some folk think that using arbitrary abbreviations make them
sound fun, cool and trendy.....

At least that's what I thnk.

James
maverik
2008-12-04 11:08:33 UTC
Permalink
Post by cnoe
Post by maverik
Post by Joachim Schmitz
Post by maverik
Post by cnoe
So, 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 ?
There is vector in C language. What do you mean? Is it std::vector?
Which is C++, not C
I know. May be cnoe meand std::vector (from C++)? Just a guess.
yes, ppl it's
std:: vector
let me know that .
If you write in C++ you probably should ask in the c.l.c++ group. If
you write in C, you cann't use std::vector
s***@gmail.com
2008-12-04 11:53:11 UTC
Permalink
Post by cnoe
Post by maverik
Post by Joachim Schmitz
Post by maverik
Post by cnoe
So, 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 ?
There is vector in C language. What do you mean? Is it std::vector?
Which is C++, not C
I know. May be cnoe meand std::vector (from C++)? Just a guess.
yes, ppl it's
std:: vector
let me know that .
I 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. The 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
limitation is allocating the array dynamically:

int* a = malloc(sizeof(int) * 10);

and then later resizing it with realloc:

int* new_a = realloc(a, sizeof(int) * 20);

std::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.

Sebastian
n***@hotmail.com
2008-12-04 12:43:52 UTC
Permalink
[X-posted to comp.lang.c and comp.lang.c++]
Post by maverik
Post by cnoe
Post by maverik
Post by Joachim Schmitz
Post by maverik
Post by cnoe
So, 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
Post by maverik
Post by cnoe
Post by maverik
Post by Joachim Schmitz
Post by maverik
There is vector in C language.
oh no there isn't
Post by maverik
What do you mean? Is it std::vector?
Post by cnoe
Post by maverik
Post by Joachim Schmitz
Which is C++, not C
yes
Post by maverik
Post by cnoe
Post by maverik
I 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 maverik
I 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 maverik
The 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 maverik
std::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)
CBFalconer
2008-12-05 00:04:20 UTC
Permalink
***@gmail.com wrote:
... snip ...
Post by s***@gmail.com
If you are talking about
std::vector<int> a;
vs.
int a[10];
there are big differences between the two. ...
Indeed. The first doesn't exist. The second declares a to be an
array of 10 ints. Bear in mind that this is c.l.c, where we
discuss the C language.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Richard Heathfield
2008-12-05 07:51:46 UTC
Permalink
Post by CBFalconer
... snip ...
Post by s***@gmail.com
If you are talking about
std::vector<int> a;
vs.
int a[10];
there are big differences between the two. ...
Indeed. The first doesn't exist.
Er, yes it does.
Post by CBFalconer
The second declares a to be an
array of 10 ints. Bear in mind that this is c.l.c, where we
discuss the C language.
You appear to believe that "not discussed on comp.lang.c" and "doesn't
exist" are isomorphic. Finding food must be a real problem for you.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
CBFalconer
2008-12-05 23:12:11 UTC
Permalink
... snip ...
Post by Richard Heathfield
Post by CBFalconer
Indeed. The first doesn't exist.
Er, yes it does.
... snip ...
Post by Richard Heathfield
You appear to believe that "not discussed on comp.lang.c" and
"doesn't exist" are isomorphic. Finding food must be a real
problem for you.
I have this peculiar (to you, apparently) habit of searching for
food in grocery stores or restaurants, rather than hardware stores,
bicycle factories, etc. Similarly I do not search for C++
information on c.l.c. Most of the users here have the capability
of extending questions and answers in such a manner as to be
topical. If you try that, you might find that things make more
sense. You will certainly reduce the amount of useless drivel you
generate.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Keith Thompson
2008-12-05 23:18:09 UTC
Permalink
Post by CBFalconer
... snip ...
Post by Richard Heathfield
Post by CBFalconer
Indeed. The first doesn't exist.
Er, yes it does.
... snip ...
Post by Richard Heathfield
You appear to believe that "not discussed on comp.lang.c" and
"doesn't exist" are isomorphic. Finding food must be a real
problem for you.
I have this peculiar (to you, apparently) habit of searching for
food in grocery stores or restaurants, rather than hardware stores,
bicycle factories, etc. Similarly I do not search for C++
information on c.l.c. Most of the users here have the capability
of extending questions and answers in such a manner as to be
topical. If you try that, you might find that things make more
sense. You will certainly reduce the amount of useless drivel you
generate.
If you're standing in a hardware store, and somebody asks you where to
find the potatoes, do you tell him that potatoes don't exist?

Continuing with the metaphor, Richard did not say or imply that one
should look for potatoes in a hardware store, merely that a claim that
potatoes don't exist is false regardless of where you're standing when
you make it.
--
Keith Thompson (The_Other_Keith) kst-***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
jameskuyper
2008-12-05 23:42:02 UTC
Permalink
Post by CBFalconer
... snip ...
Post by Richard Heathfield
Post by CBFalconer
Indeed. The first doesn't exist.
Er, yes it does.
... snip ...
Post by Richard Heathfield
You appear to believe that "not discussed on comp.lang.c" and
"doesn't exist" are isomorphic. Finding food must be a real
problem for you.
I have this peculiar (to you, apparently) habit of searching for
food in grocery stores or restaurants, rather than hardware stores,
bicycle factories, etc.
No, what is peculiar is your habit of doing the equivalent of
declaring that there's no such thing as food, just because you happen
to currently be in a hardware store. If you said that there was no
food "here" that would be a little bit better (though it doesn't take
into consideration the point of view of termites and carnivores, for
whom the typical hardware store is full of food - aka wood and
customers, respectively). You'd be more correct if you said "there's
no food for sale here". But that would have corresponded to you saying
"std::vector does not exist in C", a statement you didn't make.
Instead, you terminated the statement before saying "in C", converting
what could have been a perfectly true statement into a patently false
one.

It's perfectly true that the topic of this newsgroup is C; but anyone
who knows sufficiently little about the differences between C and C++
that they need to be told that std::vector does not exist in C, is
unlikely to guess that there was an implicit "in C" missing from your
statement. If they know that it does exist (in C++), they're just
going wonder what kind of nutcase you who would spouting nonsense like
that. Wording your statement the way you did prevents it from being
useful to anyone who actually needs to know what you tried, but
failed, to communicate.
James Harris
2008-12-06 00:33:41 UTC
Permalink
Post by CBFalconer
... snip ...
Post by Richard Heathfield
Post by CBFalconer
Indeed. The first doesn't exist.
Er, yes it does.
... snip ...
Post by Richard Heathfield
You appear to believe that "not discussed on comp.lang.c" and
"doesn't exist" are isomorphic. Finding food must be a real
problem for you.
I have this peculiar (to you, apparently) habit of searching for
food in grocery stores or restaurants, rather than hardware stores,
bicycle factories, etc. Similarly I do not search for C++
information on c.l.c. Most of the users here have the capability
of extending questions and answers in such a manner as to be
topical. If you try that, you might find that things make more
sense. You will certainly reduce the amount of useless drivel you
generate.
[OT] Eloquently put, Chuck. There's something about programming that
makes pedants of us all. Or maybe a pre-existing pedantic mind-set
predisposes one to programming. Perhaps the more pedantic head for the
lower level languages.

To continue Richard's and your food analogy:


we argue over trifles....


Sorry for the awful pun - I just couldn't help myself.

James
Phil Carmody
2008-12-06 11:57:29 UTC
Permalink
Post by CBFalconer
... snip ...
Post by Richard Heathfield
Post by CBFalconer
Indeed. The first doesn't exist.
Er, yes it does.
... snip ...
Post by Richard Heathfield
You appear to believe that "not discussed on comp.lang.c" and
"doesn't exist" are isomorphic. Finding food must be a real
problem for you.
I have this peculiar (to you, apparently) habit of searching for
food in grocery stores or restaurants, rather than hardware stores,
bicycle factories, etc. Similarly I do not search for C++
information on c.l.c. Most of the users here have the capability
of extending questions and answers in such a manner as to be
topical. If you try that, you might find that things make more
sense. You will certainly reduce the amount of useless drivel you
generate.
Inappropriate analogy.

A better one is:

You're in a vegan healthfood store (that's c.l.c), and you ask
"Do the vegeburgers contain as much protein for my growing kid
as the local butcher's freshly ground beefburgers?".
(i.e. does this language construct in your language offer the
equivalent functionality for my software project to a different
construct in another language?)

The answer "Beefburgers do not exist" is simply not helpful,
and wrong.

If I had gone into the vegan healthfood store and asked "How
long should I grill beefburgers?", then your answer would have
been appropriate. That was, however, not the case.

Phil
--
I tried the Vista speech recognition by running the tutorial. I was
amazed, it was awesome, recognised every word I said. Then I said the
wrong word ... and it typed the right one. It was actually just
detecting a sound and printing the expected word! -- pbhj on /.
maverik
2008-12-04 11:15:45 UTC
Permalink
Post by maverik
Post by cnoe
So, 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 ?
There is vector in C language. What do you mean? Is it std::vector?
Damn. I mean "There is no vector in C language"
Martin Ambuhl
2008-12-04 10:56:43 UTC
Permalink
Post by cnoe
So, what is a Vector ? how it is different from an Array ?
The term "vector" is superfluous to C. The term in physics refers to a
physical quantity having a magnitude and direction, which is equivalent
to a directed line segment and thus can be written as an n-tuple, which
is simply a 1-dimensional array.

Since any array in C is 1-dimensional, all arrays in C are vectors.
What appear to be multi-dimensional arrays in C are (1-dimensional)
arrays of (1-dimensional) arrays of ... to however many 'dimensions' are
being considered, or vectors of vectors of ....

People tend call
double x[3];
a vector (of length 3) of doubles, and
double y[3][4];
a 3x4 2-dimensional array of doubles, but in C
y is an array[3] of array[4] of doubles.
That is, y is a vector of length 3, which has
elements that are vectors of length 4 of doubles.

Very few people writing C code would use the term "vector" for a
programming construct, since it contains no information not already in
the word "array". They might use it to describe the underlying physical
reality or mathematical object that the construct represents.
viza
2008-12-04 11:27:50 UTC
Permalink
Post by Martin Ambuhl
Very few people writing C code would use the term "vector" for a
programming construct
Nonsense, the term is used in almost every C program ever written:

main( int argc, char **argv )

What do you think the v there is for? :-)
Chris Dollin
2008-12-04 11:32:16 UTC
Permalink
Post by viza
Post by Martin Ambuhl
Very few people writing C code would use the term "vector" for a
programming construct
main( int argc, char **argv )
What do you think the v there is for? :-)
Values!
--
"There's no 'we' in 'team'." Unsaid

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN
Richard Tobin
2008-12-04 13:39:52 UTC
Permalink
Post by Chris Dollin
Post by viza
What do you think the v there is for? :-)
Values!
Good try, but it's pretty clearly "vector". It matches "execv", and
the oldest man page for that I have to hand (6th edition) refers to
both "a vector of strings" and "an array of character pointers", and
in the assembler section to a "list".

(It also says that argv[argc] is -1, which has changed.)

-- Richard
--
Please remember to mention me / in tapes you leave behind.
maverik
2008-12-04 11:37:32 UTC
Permalink
Post by viza
Post by Martin Ambuhl
Very few people writing C code would use the term "vector" for a
programming construct
main( int argc, char **argv )
What do you think the v there is for? :-)
IMHO, most programmers think of it as:
1. Array of strings
2. Array of pointers to char (*argv[])
3. Array of arrays of char

or anything else but not as vector.
maverik
2008-12-04 11:38:45 UTC
Permalink
Post by maverik
Post by viza
Post by Martin Ambuhl
Very few people writing C code would use the term "vector" for a
programming construct
main( int argc, char **argv )
What do you think the v there is for? :-)
1. Array of strings
2. Array of pointers to char (*argv[])
3. Array of arrays of char
or anything else but not as vector.
You should read "most C programmers"
Phil Carmody
2008-12-04 13:23:11 UTC
Permalink
Post by viza
Post by Martin Ambuhl
Very few people writing C code would use the term "vector" for a
programming construct
main( int argc, char **argv )
What do you think the v there is for? :-)
Well, once I know the argument count, I personally
next want to look at the arguments' values, I don't
know about you.

Phil
--
I tried the Vista speech recognition by running the tutorial. I was
amazed, it was awesome, recognised every word I said. Then I said the
wrong word ... and it typed the right one. It was actually just
detecting a sound and printing the expected word! -- pbhj on /.
CBFalconer
2008-12-05 00:08:10 UTC
Permalink
Post by viza
Post by Martin Ambuhl
Very few people writing C code would use the term "vector" for a
programming construct
main( int argc, char **argv )
What do you think the v there is for? :-)
It distinguishes the name of the object (a parameter) from the name
of the other parameter, which is argc. If you wish you can replace
those names by x and y, or anything else unique, with no alteration
to the program.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Keith Thompson
2008-12-05 00:31:41 UTC
Permalink
Post by CBFalconer
Post by viza
Post by Martin Ambuhl
Very few people writing C code would use the term "vector" for a
programming construct
main( int argc, char **argv )
What do you think the v there is for? :-)
It distinguishes the name of the object (a parameter) from the name
of the other parameter, which is argc. If you wish you can replace
those names by x and y, or anything else unique, with no alteration
to the program.
Of course, but that's hardly the point, is it? argc and argv are the
conventional names for the two parameters of main(). I'm fairly sure
that the names originated as abbreviations of "argument count" and
"argument vector".
--
Keith Thompson (The_Other_Keith) kst-***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
James Harris
2008-12-05 00:51:40 UTC
Permalink
Post by viza
Post by Martin Ambuhl
Very few people writing C code would use the term "vector" for a
programming construct
main( int argc, char **argv )
What do you think the v there is for? :-)
Well, it looks like you are right - or at least more right than the
four people so far who have chosen to argue against your suggestion.
Of course it's hard to be dogmatic as the name is only a convention
but here are two sources that support what you say. First the glossary
at

http://www.c-faq.com/sx1/

calls argv an "array ('vector') of command-line arguments."

(By the way, is this the current C FAQ? I couldn't see any recent
periodic posts to c.l.c telling people where to find the FAQ.)

Second, K&R 2nd ed in sect 5.10 says the second parameter is named
"argv, for argument vector."

Speaking of arguments I think you've won this one. :-)

James
viza
2008-12-05 02:49:52 UTC
Permalink
Hi
Post by James Harris
Post by viza
main( int argc, char **argv )
What do you think the v there is for? :-)
Second, K&R 2nd ed in sect 5.10 says the second parameter is named
"argv, for argument vector."
Being a fully-bearded physicist (like both Kernighan & Ritchie) I just
instinctively read it as "vector".

viza
Flash Gordon
2008-12-05 07:34:14 UTC
Permalink
James Harris wrote, On 05/12/08 00:51:

<snip>
Post by James Harris
http://www.c-faq.com/sx1/
calls argv an "array ('vector') of command-line arguments."
(By the way, is this the current C FAQ? I couldn't see any recent
periodic posts to c.l.c telling people where to find the FAQ.)
<snip>

Yes, c-faq.com is the current location of the FAQ. Steve recommends
using the link http://www.c-faq.com/ as everything else is subject to
change (although I don't think it has changed since he announced it).
--
Flash Gordon
If spamming me sent it to ***@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Richard Heathfield
2008-12-05 08:06:28 UTC
Permalink
Post by Flash Gordon
<snip>
Post by James Harris
http://www.c-faq.com/sx1/
calls argv an "array ('vector') of command-line arguments."
(By the way, is this the current C FAQ? I couldn't see any recent
periodic posts to c.l.c telling people where to find the FAQ.)
<snip>
Yes, c-faq.com is the current location of the FAQ. Steve recommends
using the link http://www.c-faq.com/ as everything else is subject to
change (although I don't think it has changed since he announced it).
*Everything* about the C FAQ is subject to change, including whether or not
it is subject to change.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Richard Tobin
2008-12-04 13:24:42 UTC
Permalink
Post by Martin Ambuhl
What appear to be multi-dimensional arrays in C are (1-dimensional)
arrays of (1-dimensional) arrays of ... to however many 'dimensions' are
being considered, or vectors of vectors of ....
But they are also multi-dimensional arrays, unless section 6.5.2.1
(Array subscripting) of C99 is mistaken.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
James Harris
2008-12-04 11:25:59 UTC
Permalink
Post by cnoe
So, 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 ?
In computing terms Vector has at least two distinct meanings. As you
know now this is not relevant to C. Try asking in comp.programming.

James
James Kuyper
2008-12-04 11:30:09 UTC
Permalink
Post by cnoe
So, 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 ?
An array is a concept with many meanings, some of which are used in C. A
vector is a concept with many meanings, none of which are used in C,
though C arrays can be used to represent mathematical vectors.

In C++, there's a standard library template class called std::vector<>.
It is just a generalization of the C concept of an array; it carries
none of the additional meanings that apply to mathematical vectors
(std::valarray<> is actually closer to the mathematical concept of a
vector). If your question is about std::vector<>, you should take it to
comp.lang.c++.
Malcolm McLean
2008-12-06 17:33:08 UTC
Permalink
Post by cnoe
So, 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 ?
In C++ a "Vector" is a gift-wrapped array. Specifically it flags an error if
you try to access it beyond array bounds, it carries length information with
it, and you can expand it or shrink it without doing memory reallocation
yourself.

Probably the C++ people chose the term "Vector" simply because "array" is
already in common use for the raw C construct. A C array is simply a list of
variables arranged contiguously in memory. If you try to read or write
beyond array bounds, you get "undefined behaviour" which is a segfault if
you are lucky, a difficult to track bug if unlucky.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
James Kuyper
2008-12-06 18:17:13 UTC
Permalink
Post by Malcolm McLean
Post by cnoe
So, 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 ?
In C++ a "Vector" is a gift-wrapped array. Specifically it flags an
error if you try to access it beyond array bounds,
It permits checked access using the at() member function. It also allows
unchecked access through the overloaded [] operator. In my very limited
amount of C++ experience, I've seen a lot more use of [] than of at().
Loading...