void skip(char *msg)
{
puts(msg+6);
}
char *message="Don't call me";
skip(message);
My doubt is why we don't use
puts(*(msg+6)) to display text from 7th character onward;
according to me (msg+6) refers to memory and *(msg+6) content
void skip(char *msg)
{
puts(msg+6);
}
char *message="Don't call me";
skip(message);
My doubt is why we don't use
puts(*(msg+6)) to display text from 7th character onward;
according to me (msg+6) refers to memory and *(msg+6) content
*msg
is essentially a reference to a single char, not to the string of char's. due to this char *
and char[]
are essentially the same thing and you don't need to dereference character pointer in C because compiler automatically print fully string from given base address upto '\0' not get. you can also refer this for more info .
#include <stdio.h>
void skip(char *msg) {
puts(msg + 6);
}
int main() {
char *message = "Don't call me";
skip(message);
}
This is what you can find in puts manual:
int puts(const char *s);
as you can see it also expects pointer to a content as a parameter, rather than an actual value.