c - Why does the sizeof operator give different outputs -


I'm learning the basics of C for a course that I'm taking up soon, and right now I'm pointers and arrays I'm learning about I am using several contexts to know it, but in the book "C in Head First", I have the following:

  chars [] = "How big is this? "Char * t = s; Printf ("% i \ n", size (s)); / * Returns 15 * / printf ("% i \ n", Size (T)); / * Returns 4 or 8 * /  

All is well, but if I change the previous line to:

  printf ("% i \ N ", size (* s)); / * 1 Return (even on my company) * /  

So my question is different why? Apologizes that this is really a basic thing, but I have not yet wrapped my mind around the concept of pointers.

size four array, s , which is 14 char s, plus one for the null terminator; Ergo 15 bytes Returns the size of

sizeof (t) char indicator t . s is not known to the length of s because when you decrease its value from s , s one From an array type to an indicative type, the length of information in the process is lost. As you've found, the pointers may vary in size, depending on the target platform.

sizeof (* s) and sizeof (* t) address of the first char in both the dereference array, single Give char sizeof (char) == 1, because a char per definition is a single byte.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -