well , i know java, but im new to c.

i came across this while learning c :

int my_function(const char *str1){

unsigned char c1;

c1 = (*(unsigned char *) str1);

}

well i suppose this code is casting from a string to the character value of it but what about the * symbols.

i now know a bit about pointers (i.e. int *ip where ip is a pointer to an integer type) but what's with this line of code :c1 = (*(unsigned char *) str1);

thx in advance :)

*str is the character pointed to by str , which has type const char . The (unsigned char *) cast tells the compiler to convert str from a pointer to a const plain char to a pointer to an unsigned char (the "conversion" itself is likely trivial, though I won't say "it pretends" or other variants of this phrase that some might use). The leftmost * is used to dereference this pointer; that is, obtain the value of the unsigned char being pointed to.

Thank you Dave, you made things much more clearer :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.