-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

BenMorel
  • 34,448
  • 50
  • 182
  • 322
sandy
  • 1
  • 3

3 Answers3

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 .

Community
  • 1
  • 1
Vikas Verma
  • 3,626
  • 6
  • 27
  • 40
0
#include <stdio.h>

void skip(char *msg) {
    puts(msg + 6);
}
int main() {
    char *message = "Don't call me";
    skip(message);
}
Engineer
  • 1
  • 1
-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.

Jovik
  • 4,046
  • 6
  • 24
  • 24