#include <stdio.h>
int main()
{
char a[] = "atnyla";
printf("%s\n", a);
return 0;
}
atnyla
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:
#include line includes the standard input/output library in the program.main() function is the entry point of the program.a is declared and initialized with the string "atnyla".printf() function is used to display the contents of a using the %s format specifier.
%s is a format specifier used to display a string of characters.\n character is used to insert a newline after the output is printed.return 0; statement terminates the program and returns 0 to the operating system indicating that the program executed successfully.First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.