>I know what you are saying, but would you mind listing examples.
The simplest example is an array of pointers. Do you want to compare the value of the pointers or the value of the addresses pointed to:
#include <stdio.h>
#include <string.h>
int main ( void )
{
static int a = 10;
static int b = 20;
static int c = 10;
static int d = 20;
int *aa[2] = { &a, &b };
int *ab[2] = { &c, &d };
if ( memcmp ( aa, ab, 2 * sizeof ( int ) ) == 0 )
puts ( "Equal" );
else
puts ( "Not equal" );
return 0;
}
Most likely it's the former, so memcmp would give the wrong answer unless by some coincidence both arrays all have pointers that reference the same addresses.
>It'll be something like this
No it wouldn't, that code is awful. The concept is sound, but the implementation sucks. Here are a few reasons why:
>#include <iostream.h>
Not C++.
>#include <conio.h>
No portable.
>void main()
Undefined.
>clrscr();
VERY nonportable.
>cin>>n;
Not robust.
>for(i=1;i<=n;i++)
Poor style, not idiomatic.
>cin>>a[i];
Not robust, difficult to recover from on error.
>g=1;
>while(g==1)
>{ g=0;
Confused and awkward.
>getch();
Not portable and stupid because there's a standard alternative that works just as well.
And on top of that, you didn't use code tags...