Can a pointer to a string be used in a printf?

前端 未结 4 555
梦谈多话
梦谈多话 2021-01-31 10:23

I am thinking of something like:

#include 
#include 
#include 

int main(void) {
    //test pointer to string
    c         


        
4条回答
  •  终归单人心
    2021-01-31 11:02

    printf("%s\n", ptr);
    

    Is this what you want?

    By the way, from printf(3), here's the documentation for the s conversion specifier (i.e %s):

    If no l modifier is present: The const char * argument is expected to be a pointer to an array of character type (pointer to a string). Characters from the array are written up to (but not including) a terminating null byte ('\0'); if a precision is specified, no more than the number specified are written. If a precision is given, no null byte need be present; if the precision is not specified, or is greater than the size of the array, the array must contain a terminating null byte.

提交回复
热议问题