Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Whats the difference between const char *p, char const *p, and char * const p?

char const difference
0
Posted

Whats the difference between const char *p, char const *p, and char * const p?

0

The first two are interchangeable; they declare a pointer to a constant character (you can’t change any pointed-to characters). char * const p declares a constant pointer to a (variable) character (i.e. you can’t change the pointer). Read these declarations “inside out” to understand them; see question 1.21. References: ISO Sec. 6.5.4.1 Rationale Sec. 3.5.4.1 H&S Sec. 4.4.4 p. 81 comp.lang.c FAQ list · Question 11.11 Q: I’ve got the declarations typedef char *charp; const charp p; Why is p turning out const, instead of the characters pointed to? A: typedef substitutions are not purely textual. (This is one of the advantages of typedefs; see question 1.13.) In the declaration const charp p; p is const for the same reason that const int i declares i as const. The typedef’ed declaration of p does not “look inside” the typedef to see that there is a pointer involved. Additional links: further reading References: H&S Sec. 4.4.4 pp. 81-2 comp.lang.c FAQ list · Question 11.11b Q: What’s t

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123