Search the Q&A Archives

# Does char *p; *p = "hello"; produce a logical error? ...

 Question by pearl Submitted on 10/12/2003 Related FAQ: comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Rating: Not yet rated Rate this question: N/A Worst Weak OK Good Great Does char *p;      *p = "hello"; produce a logical error? why?

 Answer by Himanshu Dhingra Submitted on 11/5/2003 Rating: Rate this answer: N/A Worst Weak OK Good Great Yes. p will point to certain memory location that will contain the address of the string . which certainly you don't require.

 Answer by harish Submitted on 3/10/2004 Rating: Not yet rated Rate this answer: N/A Worst Weak OK Good Great when u say char*p p is the character pointer. it will hold the address of a memory loction where a character can be stored. we can say char*p ="hello" in this case we are declaring p as pointer and storing the characters of the string in continuous locations.mentioning the string itself will give the address of the string. if u say *p it becomes derefrencing a pointer.when u use a * with a pointer it will give u the value pointed by that pointer.so *p ="hello",will show an error.

 Answer by Algebraic Extension Submitted on 2/10/2005 Rating: Not yet rated Rate this answer: N/A Worst Weak OK Good Great Do you think that's a good ides, what you are proposing here?

 Answer by l.gnanasekar Submitted on 5/20/2005 Rating: Not yet rated Rate this answer: N/A Worst Weak OK Good Great char *p; *p="Hello"; It produce logical error because *p points the single value of the p. Here we can assign a single value only like     *p='h';     *p=65;     //etc. we cannot assign address of the string.

Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.

FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.