C language: returns the pointer to the first element of two arrays, and outputs this value, array pointer
//
// Main. c
// Pointer_search
//
// Created by ma c on 15/8/2.
// Copyright (c) 2015 bjsxt. All rights reserved.
// Requirement: Compare the elements in two ordered arrays by searching the pointer and output the first identical element value in the two arrays.
# Include <stdio. h>
Int * searchSameElement (int * a, int * B, int len1, int len2 );
Int main (int argc, const char * argv [])
{
Int a [] = {4, 51, 8, 6, 7, 10 };
Int B [] = {80, 8, 10, 90, 7, 10, 51 };
Int len1 = sizeof (a)/sizeof (a [0]);
Int len2 = sizeof (B)/sizeof (B [0]);
Int * pt = searchSameElement (a, B, len1, len2); // returns the first address of the same value.
If (pt)
Printf ("% d \ n", * pt );
Else
Printf ("the same number don not find! \ N ");
Return 0;
}
Int * searchSameElement (int * a, int * B, int len1, int len2)
{
Int * pa =;
Int * pb = B;
While (pa ++) <(a + len1 ))
{
While (pb <(B + len2 ))
{
If (* pa! = * Pb)
{
Pb ++;
}
Else
{
Return pa;
}
}
}
Return 0;
}