-3
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

4
  • 5
    Yes, but puts wants the 'memory' (or rather, a pointer). *(msg + 6) is but a single character, not a string. Commented Sep 2, 2014 at 19:23
  • then what about printf("%s",msg+6); Commented Sep 2, 2014 at 19:25
  • @sandy: int printf(const char *restrict format, ...); Commented Sep 2, 2014 at 19:28
  • @sandy Same story, printf expects a (character-)pointer for every %s in the format. I don't understand what you're not understanding... Commented Sep 2, 2014 at 19:28

3 Answers 3

0

*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 .

Sign up to request clarification or add additional context in comments.

2 Comments

@vikash Can u please elaborate ur statement...char * and char [] are essentially same
0
#include <stdio.h>

void skip(char *msg) {
    puts(msg + 6);
}
int main() {
    char *message = "Don't call me";
    skip(message);
}

1 Comment

Please consider adding an explanation.
-1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.