Implicit type conversion – tricky scenario

Here are some of the scenarios where the implicit  type conversion can be unintuitive  and tricky.

  • implicit conversion between int, float and bool
    #include <iostream>
    
    void print(char x){
      std::cout << "in the print method that has char arg\n";
    
    }
    
    void print(int x){
      std::cout << "in the print method that has int arg\n";
    }
    
    void print(bool x){
      std::cout << "in the print method that has bool arg\n";
    }
    
    int main(){
    int x =1;
    char ch = 'c';
    char * c = &ch;
    print(*c); // in the print method that has char arg
    print(*c+1); //in the print method that has int arg
    return 0;
    }

Author: Saurabh Purnaye

Sr. Developer @NYSE @ICE_Markets. Low Latency Trading, Linux, C++, Python, Ruby. pursuing certificate in #QuantFinance and Passed CFA L1

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s