Jump to content

learning int(x), float(x) cast

- - - - -

  • Please log in to reply
1 reply to this topic

#1
jackson6612

jackson6612

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 304 posts
Hi

Please help me with the queried in blue. Thank you. By the way, I'm not getting the editor toolbar and I had to use captcha to enter the forums.


//learning int(x), float(x), etc.cpp


#include <iostream>

#include <cstdlib>


using namespace std;


int main()

{

    float x = 4.5;


    cout << "x = " << x << endl;


    cout << "x = " << int(x) << endl;

    [b][color="blue"]//as you can see "x" is being cast, what's this type of cast called?[/color][/b]


    cout << "x = " << static_cast<int>(x) << endl;


    int(y)=8;

    [b][color="blue"]//what's the advantage of using this syntax to use declare and initialize a variable?[/color][/b]


    cout << "y = " << y << endl;


    system("pause");

    return 0;

}


Edited by jackson6612, 24 November 2011 - 05:51 AM.

I'm an outright beginner, learning C++. Using Win XP Pro and Code::Blocks. Be nice to me, please.:)

#2
AKMafia001

AKMafia001

    Programmer

  • Members
  • PipPipPipPip
  • 119 posts
Check this and this also.
I think i'm able to write a code for printing "Hello, World!". Proud of that!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users