mercredi 8 avril 2020

Difference between narrowing and truncation in C++?

I've been going through a book (C++ Programming Language Stroustrup 4th ed). An example given in a section related to Initialization as below:

void f(double d, int i)
{
    int a{ d };     // error : possible truncation
    char b{ i };    // error : possible narrowing
}

What exactly is the difference between truncation and narrowing?

Aucun commentaire:

Enregistrer un commentaire