Why don't I need to dereference a character pointer in C before printing it?

后端 未结 6 1241
遇见更好的自我
遇见更好的自我 2020-12-13 11:19

Why does this code work? I would expect that I would need to dereference ptr, printf(\"%s\\n\", *ptr); before I could print it out, but I get a

6条回答
  •  心在旅途
    2020-12-13 12:08

    When you declare char prt = name thats where you are dereferencing it. the "" here isn't part of the variable just a way to show you want what that variable points to. If you were to put the *prt again in your printf you are doing it twice. name is an array of characters and *ptr is a dereferenced pointer to those characters.

    Hope that explaination helps :-)

提交回复
热议问题