"searching for duplicates in an array" is not a very good problem statement.
Exactly what output do you want?
"Yes" or "no" if there is at least one duplicate or not?
A count of how many duplicates there are?
A list of the indices of the duplicates?
Do you want the duplicates removed from the array?
You are determining the array size in a strange way.
1 2 3 4
|
// Instead of this:
int size = *(&myarr + 1) - myarr;
// We usually do this
int size = sizeof myarr / sizeof *myarr;
|
Don't set bools to 0 and 1; use false and true.
x should only go up to x < size. And l should only go up to l <= sizebool. (And the l loop should presumably be after the x loop, not inside it.)
y doesn't make any sense. Instead, you should just use x.
Don't do an
if/else if when the
else if is the opposite condition of the if. Just use an
if/else.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
// Instead of this
if (myarr[x] == myarr[x - 1])
arrpos[x] = true;
else if (myarr[x] != myarr[x - 1])
arrpos[x] = false;
// do this
if (myarr[x] == myarr[x - 1])
arrpos[x] = true;
else
arrpos[x] = false;
// But actually, in this case you can do this
arrpos[x] = (myarr[x] == myarr[x - 1]);
|
But it's unlikely that you need arrpos at all, unless that bool array itself is the output you are seeking.