This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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

 
Ranch Hand
Posts: 91
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: 13851
312
  • 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: 23919
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: 91
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: 91
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: 23919
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: 91
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: 91
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: 23919
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: 75644
354
  • 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.
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic