#include<string.h>
#include<stdio.h>
int main()
{
char* charPtr="see me";
printf("%s\n", charPtr);
printf("%d", charPtr);
return 0;
}
I do not understand the line:
char* charPtr=”see me”;
how is the memory allocated?
Is 7 bytes of memory allocated and the pointer is allocated to the first byte? and
I know the sizeof(char*) is 4bytes and how does it matter here and what does it influence in allocation of memory?
Some one please help me.thanks…
charPtris a pointer to an string literal “see me” which resides somewhere in implementation defined memory region. This string literal should not be modified and any attempt to do so leaves you with an Undefined Behavior.Since
charPtris a pointer you cannot usesizeof()to determine the length of the string literal. If you do so, What you get is the memory occupied by the pointer and not by the string. You will need to usestrlen()if you need to get the length of the string.