7 min read

Before understanding what c and s are in c programming, one should have some basic knowledge about the programming itself.
C is a programming language developed by Dennis Ritchie in 1969 at the AT&T Bell Labs. It’s known as a function-driven programming language. It has lasting use in operation systems, device drivers, and protocol stacks. Moreover, it’s commonly used in computer architectures ranging from large supercomputers to small microcontrollers and embedded systems.
C is considered an imperative procedural language that supports structured programming, lexical variable scope, and recursion with a static type system. It was designed to provide low-level access to memory and language constructs that can map easily to machine instructions with minimum runtime support. Furthermore, this programming language was also designed to encourage cross-platform programming.
Since 2000, C has been ranked among the top languages, which proves that it’s quite an incredible tool.
Here is a list of some of the best features of the C programming language:
As we understand what C programming is and what it is supposed to do, let’s dive into what c and s are.
%c is used for a single character, while %s is used for a string. A string is a sequence of characters that are stored in the contiguous memory locations. %c is used for scanning the character type input from the users, moreover using %c means, that only a single character will be printed. The main difference between these two specifiers is that %s is expected a pointer with a null-terminated string, while %c is expected of a character.
%c
denotes a Character%s
denotes a StringMoreover, in C, String, as well as characters, are declared by using char
a keyword.
There are other format specifiers that one should know. Thus, here is a table for some of them.
Format Specifier | Used For |
%hi | Short (signed) |
%hu | Short (unsigned) |
%Lf | Long double |
%n | Prints nothing |
%i | A decimal integer (it detects the base automatically) |
%x | A hexadecimal (base 16) integer |
%d | A decimal (base 10) integer |
Keep reading to know more.
%c is a format specifier, and it denotes a character, meaning when we use it, only one character will be printed. In %c, a single character is a single symbol that can either represent a letter or a number.
When a user enters a single character in the program, the character itself can’t be stored. Instead, an integer value (ASCII value) will be stored. Furthermore, when we put that value by using the %c text format, the character that the user entered will be displayed. %c is used to scan the character type input from the users.
There is a %c specifier in other programming languages, which means the same.
Yes, there is another programming language as well. C is the basic one. However, it doesn’t mean it doesn’t work as well as other programming languages.
A video will teach you how to choose the best programming language and talk about almost all programming languages.
%s is a format specifier which is used for a string, by string it means, a set of characters. These characters are stored in the contiguous memory locations when the users enter those characters.
If you are using %s, then the set of characters will print till the compiler gets ‘/0’ (end of the string) when you are declaring a string by default ‘/0’ attached in the string, or else if ‘/0’ isn’t there then the compiler will be printing the whole memory.
One should remember that A, String, when declaring explicitly, requires an End of String Character. \0
.
Furthermore, Contiguous Variables, which include an array of strings, don’t require Address Of as well as an operator for their usage in functions, like printf()
and scanf()
. In addition, an Array Name can be used to refer to the first element.
Lastly, the array or string of characters must begin from {}
instead of []
.
Just like %s and %c format specifiers, there are many more that are needed for different purposes, one of them is %d. As %c is used for a single character and %s is used for a string, %d is used for the specification of a signed decimal integer.
%d can tell the print function that the corresponding argument will be treated as an integer value. The type of such corresponding argument should be int.
What does a format specifier even do? A format specifier can tell you what type of data should be stored and printed, and %d represents the signed decimal integer.
We use printf() function with the %d format specifier to put or show the value of an integer variable. Same as %c is used to show a single character, %f is for float variables, %s is for string variables, and %x is for hexadecimal variables.
%s means a string character, while %d means a signed decimal integer. Every format specifier is there for a reason and the reason for %s is that it’s used if the user has to enter a string of characters, while %d is used to specify the signed decimal integer.
One should know some things about %s and %d format specifiers.
\0
.
We appreciate you taking the time to share your feedback about this page with us.
Whether it's praise for something good, or ideas to improve something that
isn't quite right, we're excited to hear from you.