• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 110
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 15524
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 110
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 110
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
at time 7:14 in the video.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 110
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 110
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic