In C programming, both %c and %s are format specifiers used in the printf() and scanf() functions to format input and output.
The %c format specifier is used to display a single character, while %s is used to display a string of characters. Here are some more details:
- %c: This format specifier is used to display a single character, which can be a letter, a digit, a punctuation mark, or a whitespace character. When used with printf(), it expects a char type argument, and when used with scanf(), it expects a pointer to a char type variable as an argument.
- %s: This format specifier is used to display a string of characters, which is a sequence of one or more characters terminated by a null character ('\0'). When used with printf(), it expects a char array (string) as an argument, and when used with scanf(), it expects a pointer to a char array (string) as an argument.
Here is an example to illustrate the difference:
char letter = 'A';
char name[] = "John";
printf("The letter is %c\n", letter); // Output: The letter is A
printf("The name is %s\n", name); // Output: The name is John
In the first printf() statement, the %c format specifier is used to display the value of the char variable
'letter', which is 'A'. In the second printf() statement, the %s format specifier is used to display the value of the
char array 'name', which is the string "John".