Array vs Vector

C

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 ?


Thnx
 
M

maverik

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?
 
M

Martin Ambuhl

cnoe said:
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.
 
M

Martin Ambuhl

cnoe said:
yes, ppl it's
^^^
A careful writer would write "people".
A programmer who is not a careful writer is a poor programmer.
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.
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.
 
M

maverik

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
 
J

James Harris

^^^
A careful writer would write "people".
....


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
 
J

James Harris

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
 
V

viza

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? :)
 
J

James Kuyper

cnoe said:
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++.
 
C

Chris Dollin

viza said:
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? :)

Values!
 
M

maverik

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? :)

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.
 
S

s0suk3

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
 
G

Guest

[X-posted to comp.lang.c and comp.lang.c++]


a vector is a one dimensional matrix

oh no there isn't
What do you mean? Is it std::vector?

yes

I've no idea what that means
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

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);

so you *can* resize an array. Or at least treat a resizable
block of memory like an array
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)
 
P

Phil Carmody

viza said:
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? :)

Well, once I know the argument count, I personally
next want to look at the arguments' values, I don't
know about you.

Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top