Write a program that demonstrates the variety of ways that a string can be printed.

C Programming Language String in C Language (Article) String in C Language (Program)

744

Program:

#include <stdio.h>

int main()
{
  char s[]="Hello, World";

  printf(">>%s<<\n",s);
  printf(">>%20s<<\n",s);
  printf(">>%-20s<<\n",s);
  printf(">>%.4s<<\n",s);
  printf(">>%-20.4s<<\n",s);
  printf(">>%20.4s<<\n",s);
  return 0;

}

Output:

>>Hello, World<<
>>        Hello, World<<
>>Hello, World        <<
>>Hell<<
>>Hell                <<
>>                Hell<< 

Explanation:

None

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.