0
char srch(char x[],char k){
int i=0;
while(x[i]!='\0')
{
if(k==x[i])
{
const char *h=&(x[i]);
const void *l = h;
cout<<"\n\nTHE CHARACTER "<<x[i]<<" FOUND AT ADDRESS "<<l<<"\n\n\n";
exit(0);
}
i++;
}
return NULL;
}
int main(){
system("cls");
char str[20],ch;
cout<<"ENTER THE STRING:-\n";
gets(str);
cout<<"ENTER THE CHARACTER WHICH YOU WANT TO SEEK:-\n";
cin>>ch;
srch(str,ch);
if(NULL);
cout<<"\n\nCHARACTER NOT FOUND ";}
現在,如果我的字符串是「tarun」,並且我要查找的字符是'a',那麼它完全顯示'a'的地址。 但 如果我用這個代替我SRCH功能: -void *和char *之間的區別*
char srch(char x[],char k){
int i=0;
while(x[i]!='\0')
{
if(k==x[i])
{
const char *h=&(x[i]);
const char *l = h;
cout<<"\n\nTHE CHARACTER "<<x[i]<<" FOUND AT ADDRESS "<<l<<"\n\n\n";
exit(0);
}
i++;
}
return NULL;}
然後代替地址,它顯示了阿倫。 爲什麼這發生在我用char *而不是void *?