Dynamic Memory allocation to string, gives out incorrect size : <p>I try to dynamically allocate memory to a string but when I print out the size it shows 4 instead of the (11+1) bytes that should be allocated. Why does this happen? The string prints out just fine.</p>

<pre><code>#include&lt;stdio.h&gt;
#include&lt;stdlib.h&gt;
#include&lt;string.h&gt;

int main(){
char c, *string;
int i=0, a=1;

printf("\nEnter the string : ");

string = (char *) malloc (sizeof(char));
while(c != '\n'){
    c = getchar();

    string = (char *) realloc (string, sizeof(char) * a);

    string[i] = c;

    a++, i++;
}
string[i] = '\0';

puts(string);

printf("\n%d", sizeof(string));

}

Input  : Sample Text
Output : 
    Sample Text
    4
</code></pre>
