C Programming Tutorial 39 – Implicit Type Promotion

The previous video was foundational to this video, so go watch that! Essentially, casting is when something of a certain data type is converted to a different data type.

This video is going to be showing examples of both implicit casting and explicit casting.

When you study implicit conversion in C, you will likely come across the term promotion.

This article talks about implicit conversion, and the section on promotion talks about what data types can be converted to other data types without loss of information.

http://en.cppreference.com/w/cpp/language/implicit_conversion
 
A common example of this is when we pass floats to functions.
 
float x = 50.0f; // You can put the f here if you want to be specific that this is a float, but either way should work just the same).
 
printf(“%f”, x);
 
The printf function actually takes the x as a double. This means that 50.0f is promoted to 50.0. If we are talking about constant values, a float value always has an f. If you leave the f off, it is assumed to be of type double. You can use the %f conversion character for both floats and for doubles because they are actually always being printed as doubles… Even if you pass in a float.
 
Now, it’s important to understand that the actual value or data type does not change. The variable x is still of type float.
 
Another common type of implicit conversion is when we are doing assignment. If we have something such as this:
 
double age = 60;
 
The integer 60 is implicitly casted to a double. That’s because an integer can fit inside of a double without losing data.
 
Sometimes, it’s not that easy and we risk losing data. That’s what we are going to be talking about in the next video.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

HELP ME! http://www.patreon.com/calebcurry

Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter

Donate!: http://bit.ly/DonateCTVM2.

~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~

More content: http://CalebCurry.com
Facebook: http://www.facebook.com/CalebTheVideoMaker
Google+: https://plus.google.com/+CalebTheVideoMaker2
Twitter: http://twitter.com/calebCurry

Amazing Web Hosting – http://bit.ly/ccbluehost (The best web hosting for a cheap price!)

source by Caleb Curry

c programming tutorial

Mourad ELGORMA

Fondateur de summarynetworks, passionné des nouvelles technologies et des métiers de Réseautique , Master en réseaux et système de télécommunications. ,j’ai affaire à Pascal, Delphi, Java, MATLAB, php …Connaissance du protocole TCP / IP, des applications Ethernet, des WLAN …Planification, installation et dépannage de problèmes de réseau informatique……Installez, configurez et dépannez les périphériques Cisco IOS. Surveillez les performances du réseau et isolez les défaillances du réseau. VLANs, protocoles de routage (RIPv2, EIGRP, OSPF.)…..Manipuler des systèmes embarqués (matériel et logiciel ex: Beaglebone Black)…Linux (Ubuntu, kali, serveur Mandriva Fedora, …). Microsoft (Windows, Windows Server 2003). ……Paquet tracer, GNS3, VMware Workstation, Virtual Box, Filezilla (client / serveur), EasyPhp, serveur Wamp,Le système de gestion WORDPRESS………Installation des caméras de surveillance ( technologie hikvision DVR………..). ,

7 réflexions sur “C Programming Tutorial 39 – Implicit Type Promotion

  • novembre 9, 2020 à 11:10
    Permalien

    Hmm, I understand that X was promoted from a float to a double, but what does the variable name "pizza" have to do with "x"? How does "x" get stored as "pizza"? What if there's double x, and double y, are they both stored in in double pizza? Is double pizza like a parent directory in this? A bit confused on that point!

    Répondre
  • novembre 9, 2020 à 11:10
    Permalien

    Each video – a stream of complete nonsense from the very beginning! Implicit conversion when passing a `float` value for a `double` argument is not a "promotion" at all. It is an ordinary plain implicit conversion. The term "promotions" in C has specific meaning, and it is reserved to integers only and it happens only to operands of binary arithmetic operators. Finally, why are you using a C++ page about "promotions", when the topic is C?

    Répondre
  • novembre 9, 2020 à 11:10
    Permalien

    I seriously wish you'd post the actual code snippet or something so I could pay more attention to what you say and less attention as to what to type – yeah, I'm that lazy programmer who hasn't figured a way to script screen-scraping a video for this LOL

    BTW, your website newsletter sign-up doesn't appear to work.

    Répondre
  • novembre 9, 2020 à 11:10
    Permalien

    Oh man, you have to read this article first. It's not the type promotion, it's implicit type conversion, which is completely different thing.

    Répondre

Laisser un commentaire