String printing : %s Example Program
C Programming Language Overview of C Language (Article) Overview of C Language (Program)
956Program:
#include int main() { char a[] = "atnyla"; printf("%s\n", a); return 0; }
Output:
atnyla
Explanation:
The %s format specifier is implemented for representing strings. This is used in printf() function for printing a string stored in the character array variable. When you have to print a string, you should implement the %s format specifier.
printf("%s",<variable name>);
The given code is a C program that declares a character array a
and initializes it with the string "atnyla". The printf()
function is then used with the %s
format specifier to print the contents of the a
array to the console.
Here's how it works:
- The
#include <stdio.h>
line includes the standard input/output library in the program. - The
main()
function is the entry point of the program. - The character array
a
is declared and initialized with the string "atnyla". - The
printf()
function is used to display the contents ofa
using the%s
format specifier.%s
is a format specifier used to display a string of characters.
- The
\n
character is used to insert a newline after the output is printed. - Finally, the
return 0;
statement terminates the program and returns 0 to the operating system indicating that the program executed successfully.
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.