Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 9:16 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: Type Conversion
PostPosted: Thu Nov 13, 2008 2:36 pm 
Offline
Beginner
User avatar

Joined: Sun May 25, 2008 5:34 pm
Posts: 95
Has thanked: 2 time
Have thanks: 1 time

Code:
/*
* Type conversion games. 
*/
#include <stdio.h>

main()
{
        /* Meaningless numbers. */
        short s = -41;
        int i = 9;
        double d = 4.27;
        double ld = 4983.22;
        long l = 17;
        long long ll = 170;
        unsigned ui = 48;

        /* When using printf, you must specify the size for items longer
           than int or double.  Many incorrect combinations work anyway,
           but it's a good idea to get it right. */
        printf("A: %d %ld %lld %f %lf\n", i, l, ll, d, ld);

        /* Operators generally convert to the longer type, but you can
           force other conversions with casts. */
        printf("B: %f %d %d %f %f\n",
               i * d,
               i * (int)d,
               i / 12,
               i / 12.0,
               (double)i / 12);

        /* Conversion will convert to the left type. */
        i = d;
        d = s;
        printf("C: %d %f\n", i, d);

        /* Unsigned values can be printed with the u conversion.  It generally
           differs from %d only for large numbers. */
        printf("D: %u\n", ui);

        /* Constants can be appended with a letter to give them the
           associated type.  This generally matters only when the
           constant you want won't fit into the unmodified length. */
        l = 1598L;
        ll = 9081092830129ll;    /* Maybe LL would be better than ll. */
        ld = 49.3981273394L;
        printf("F: %ld %lld %.12lf\n", l, ll, ld);

        /* Converting from a longer to a smaller size will also produce
           junk if the value does not fit. */
        i = 8000000;
        s = i;
        printf("G: %d == %d (sort of)\n", i, s);
}

convert from type to type in C++ :tomato:


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 set MIME type in link
 range of data type
 .dll conversion
 please get me the following Delphi to Java conversion
 Data Type in Programming
 Number Conversion
 Attributes Name Java Type
 lesson8: XSD Complex Type Mixed Content
 argument type of a program's main() method
 range of the char type

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 2 guests



Jump to:  
Previous Code Snippet | Next Code Snippet  cron




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team