C: Printing unsigned/signed integer using printf

Posted by Joys of Programming on in C/C++

Two types of integer are supported in C: signed and unsigned integers. To declare a signed integer


signed int varname;

To declare a unsigned integer


unsigned int varname;

If you do not specify a specifier with int, it is taken as signed integer. To print signed integer, you can either use i or d. For unsigned integer, use u. This is shown in the following program


#include <stdio.h>

int main()
{
 /*Unsigned Integer*/
 unsigned int uvar = 25;

 /*Signed Integer*/
 signed int svar = -25;

 /*Printing unsigned Integer*/
 printf ("%u\n", uvar);

 /*Printing signed Integer*/
 printf ("%d\n", svar);
 printf ("%i\n", svar);

 return 0;
}


Tags: , ,

Comments:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2009-2012 Joys of Programming All rights reserved.
Desk Mess Mirrored v1.8.1 theme from BuyNowShop.com.