Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

c - Pass the char* directly to printf

#include <stdio.h>

char s[]="sfksfls
";
void main()
{
        printf(s);

}

Why it can work? I just input the char pointer to printf

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

A string literal in C is a pointer to const char. printf takes a pointer to const char (plus an optional list of additional arguments). Passing it directly or through a variable makes no difference, a pointer is a pointer, it's just a number.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...