printf("%s\n", "123456789" + 3); //output: "456789"
why output this result? In the same way, what should I do if I want to output "123"? Now I'm confused. Help me.
printf() is passed a pointer to a string constant incremented by 3
printf("%s\n", "123456789" + 3);
printf() takes a format string argument followed by a variadic set of arguments. In this case, the '%s' is the first (and only) variable in the format string.
There is only one argument in the variadic section after the format string: a string constant: "12345678" which resolves to a pointer to the '1' character; however, that pointer is incremented by 3 due to the "+ 3". This moves the pointer 3 positions to the '4'.
Then, printf prints the string that starts at '4'. As the string constant is terminated by a '\0' character right after the '9', printf prints "456789"
- error when trying to apply a linq query to a list that i have as a result of another lin
- How to process dynamic tablenames
- How do I create a single list of object pairs from two lists in C#?
- Compression/Decompression string with C#
- __PRETTY_FUNCTION__ in constant expression
- Binding a bool to button visibility
- C# split byte array into separate chunks and get number of chunks [closed]
- POST data from Arduino to website
- Count elements lower than a given value in a std::set
- preferredStatusBarStyle is not working [duplicate]