Hello guys, what’s up? I have found that many of you searching about what is %c for? So, today I am going to discuss about it. Let’s start—
%c is the format specifier used for getting character or char data type. %c interprets it’s as a character value for display.
Syntax:
printf("%c",<variable name>); //for print scanf("%c",<variable name>); //for reading data from users
What is %c for - in printf()
When we use %c
in printf(), there we want a single character for output.
#include <stdio.h> int main() { char ch = 'A'; printf("%cn", ch); return 0; }
What is %c for - in scanf()
When we use %c in scanf(),
there we want a single character (a-z or, A-Z) from user, not a word nor a number.
#include <stdio.h> int main() { char ch; scanf("%c", &ch); // input is A printf("%cn", ch); return 0; }
Output
: A
Example
: print 97 (on an ASCII system) [A-65,… a=97]
#include <stdio.h> int main() { printf("%c",97); return 0; }
Output
: a
Today we learn what is %c for. I hope you guys understand everything which I have discussed earlier. So guys, that’s all for today. Later we will discuss another tutorial on c programming. Till then, take care. Happy Coding