sanskriti sirohi
last year
Sanskriticountry asked

I’ve seen %s used in some places and %c in others. What’s the difference?

Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Sanskriti,

Good observation — they’re both used in printf, but for different types of data.

  • %s is used to print a string (a sequence of characters ending with \0)

  • %c is used to print a single character

Here’s an example to make it clear:

char movie[] = "Snowpiercer";

// Prints the full string
printf("The full movie title is: %s\n", movie);

// Prints the 4th character (index 3)
printf("The fourth character is: %c\n", movie[3]);

So if you're printing the entire string, use %s.
If you're just printing one character from that string — like movie[3] — use %c.

If you have more questions, I am here to help.

C
This question was asked as part of the Learn C Programming course.