how to understand this program

There is a code snippet:
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h>

char* fun()
{
  return "awake";
}
int main()
{
  printf("%s",fun()+ printf("I see you"));
  getchar();
  return 0;
}

I do not understand why the program print out unpredictable stuff. In specific, this code segment really confuses me:

printf("%s",fun()+ printf("I see you"));
printf("I see you") returns 9, the number of the printed characters
adding that to fun(), will move the returned pointer passed the length of the char sequence it's pointing to
Hi, Bazzy:

Thanks for the reply.

Here, fun() returns pointer to char array, i.e., awake. As an example, just assume the pointer is 10, so what you suggested is that "fun() + 9" will points to 19? And printf ("%s",...) will print the stuff pointed by 19? Is my understanding correct?
Let's assume this is a fragment of your program memory:
some random stuff awake\0 some other random stuff \0
where \0 is a single byte with value 0
Assume that the first 's' of 'some' has an address value of 0

fun() returns a pointer to the first 'a' of 'awake' so 18 in this case
- notice: the pointer points to that 'a' and the value of the pointer is 18

fun()+ printf("I see you") returns 27, a pointer to the 'm' in the second 'some'

printf("%s",fun()+ printf("I see you")); will print from 27 up to the following \0, so the output would be
me other random stuff 
Topic archived. No new replies allowed.