C Compare Array Elements in Function -
this going pretty basic question i'm confused on how implement this.
for class i'm taking on c need take 2 arrays can vary in length , compare elements in separate function. (this function takes arrays parameters, not sizes) element in both arrays need set array , homecoming array (note: each array set in no elements repeat in same array). have looked how implement little bit , here of issues i'm running into.
how know end of array is?
i think saw might able {0} element in array null element. if true don't know compare element in order check null.
i think i'm supposed pass pointers first element of array because don't think c allow values of array passed, little unsure.
if pass arrays pointers, how can access arrays elements data?
when returning array main function, how can homecoming resulting function without memory beingness cleared up?
should create resulting array global, or there improve way of handling it?
thanks in advance.
your question bit vague. looks want implement set intersection have 2 sets, represented arrays, , output array implemented array.
1. how know end of array is?
in c, there no way tell. if cannot pass length function not able robust solution. need similar #2.
2. think saw might able {0} element in array null element. if true don't know compare element in order check null.
you can add together null character, value 0. check, need compare 0. not know each of array elements consist of, 1 thing watch of none of value allowed 0 anymore since reserved end of array marker.
3. think i'm supposed pass pointers first element of array because don't think c allow values of array passed, little unsure.
yes. pass pointed first element, in c array symbol.
int a[10]; // pass
4. if pass arrays pointers, how can access arrays elements data?
say passed pointer a, can access elements simple indexing a[i], grab element i.
5. when returning array main function, how can homecoming resulting function without memory beingness cleared up?
in function writing, can malloc
array , pass pointer array created malloc. malloce'd memory not deleted when function exits.
c arrays function int
No comments:
Post a Comment