C: Printing data types using printf : short, wchar_t, long double

printf is the most commonly used function while programming (for big developers at least in the designing stage). But we mostly come across the problem: “Which conversion character for char, short, pointers… and their unsigned counterparts?” Here is a program which deals with printing of all the different data types.

#include <stdio.h>

/*A program to see how diffent data types can be printed using printf
*See the conversion characters with % for the various data types
int main()
    //Character strings
   char *message="Printing different data types";
   wchar_t *wmessage=L"Wide Character string";

   char ca='A';
   wchar_t wca=L'A';

   //Integer Data types
   unsigned short usa=65535; short ssb=-32768;
   unsigned int usi=4294967295; int ssi=-2147483648;
   unsigned long long int ulli=4294967295L;long long int lli=-2147483647L;

   //Floating point Data types
   float fa=1e+37,fb=1e-37;
   double da=1e+37,db=1e-37;
   long double lda=1e+37L,ldb=1e-37L;

   int *p=&ssi;

   //Character strings

   //Character strings

   printf("%hu %hi\n",usa,ssb); //short
   printf("%hx %hx\n\n",usa,ssb);

   printf("%u %i\n",usi,ssi); //integer/long integers
   printf("%x %x\n\n",usi,ssi);

   printf("%llu %lli\n",ulli,lli); //long long integers
   printf("%llx %llx\n\n",ulli,lli);

   printf("%f %f\n",fa,fb); //float

   printf("%f %f\n",da,db); //double
   printf("%e %e\n\n",da,db);

   printf("%llf %llf\n",lda,ldb); //long double
   printf("%lle %lle\n\n",lda,ldb);

   printf("%p\n\n",p); //pointer of any data type


Here’s the output


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s