• Post Reply Bookmark Topic Watch Topic
  • New Topic

what does the * indicate in char* (very surprisingly searching web no help)  RSS feed

 
Mohammed Azeem
Ranch Hand
Posts: 56
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very quick query. What does the * in char* signify?

I'm studying a hash function that takes char* as an argument.

I have searched 30 mins on the internet trying to find out but surprisingly: NOTHING!! only char. Thumbed through all my books as well.

I know about char just want to clarify char* (is it a wildcard of some sort)?


All help appreciated.
 
Stephan van Hulst
Saloon Keeper
Posts: 7817
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you find this? This is not Java syntax. It looks like C or C++ syntax. In that case, it's a pointer to a character, signifying it's likely used to pass a string.
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that you will need to provide more context. How is this "char*" used? Is it part of a regular expression?

Henry
 
Mohammed Azeem
Ranch Hand
Posts: 56
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK so here's the code (it from a Youtube tutorial on hash tables)


unsigned int hash(char* str) {
int sum=0;
for (int j=0; str[j] != '\0'; j++) {
sum+=str[j];
}

return sum % HASH_MAX;

}
 
Mohammed Azeem
Ranch Hand
Posts: 56
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
at time 7:14 in the video.
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code in that tutorial uses the C language. And as Stephan mentioned, it is for pointer to a character. In the example, it is declaring a parameter that is a character pointer.


And BTW, I am moving this topic to the C/C++ forum for you.

Henry
 
Mohammed Azeem
Ranch Hand
Posts: 56
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh Crumbs! OK.

It's a very, very good tutorial though and I'm going to continue with it.

So what data type is char* ?

 
Mohammed Azeem
Ranch Hand
Posts: 56
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh OK. I think I'be got my head round it.

Thanks for all your help and time.
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohammed Azeem wrote:
So what data type is char* ?


It is a pointer to a character... which Java does not have an equivalent to.


Now, arguably, for the example, the equivalent would likely be a string (or character array), which is what the code is dealing with.

Henry
 
Campbell Ritchie
Marshal
Posts: 55785
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you find yourself a C/C++ tutorial and search for pointer to char or similar. Using char *str suggests to me that you are using C rather than C++. C doesn't really have a String type, rather using arrays of chars 1 larger than the number of letters in the text. The extra char is set to \0 = the null character.
I don't think that is a very good way to calculate hash codes nor a very good way to demonstrate pointers.

I think the reason you didn't find anything on the web is that search engines don't search the asterisk.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!