C++

Topic: Variable

declaring floating-point type variables

I'm at the part where you are learning the different types of variables and constants, and escape sequences, bits and bytes, all that stuff. So far I have got it pretty good, but am becoming confused on floating point types and constants.I know that when you are declaring a constant you can add suffixes to the end of the declaration to change the type. Like this:1.234f       // a float constant2.345234E28L // a long double constant  And I get that. But some example code in the book shows this:float a = 2.34E+22f;float b = a + 1.0f;I know that that code means it is declaring two variables of the type float. Variable a is 2.34e22 (2.34 X 10^22 in scientific notation). Variable b is variable a + 1. That I understand. What I don't get is why there is an f at the end of each number. I know that with constants that changes the type to float. But the type is already float because of the declaration. The word float in front of the variable name creates a variable of the type float. So why do you need an 'f' at the end. The numbers aren't considered constants. 

Browse random answers:

Scope of variables
Explain about Initialization of variables ?
Explain about Variable Declaration in C++ ?
Explain about Variable Initialization in C++:
Explain about Initializing Local and Global Variables ?
Explain about Global Variables ?
Explain about Calculations and variables ?
Why global variables are evil ?
How to store letters in a variable?
declaring floating-point type variables
What are variable declaration in c++ syntax ?
Write a function using reference variables as arguments to swap the values of a pair of integers?
How to access change a variable using pointer in C++?
Write a program to declare two integer , one float variables and assign 10, 15, and 12.6 to them respectively. It then prints these values on the screen.
What is a Variable?
What is an algorithm (in terms of the STL/C++ standard library)?
what are auto static variables and auto extern variables?
How many ways are there to initialize an int with a constant?
How do you decide which integer type to use?
How is static variable stored in the memory?( if there are 2 functions in a file,and the static variable name is same (ex var) in both the function. how is it keep seperately in the memory).
What can I safely assume about the initial values of variables which are not explicitly initialized?
What?s the auto keyword good for?
What is the difference between declaration and definition?
How variable declaration in c++ differs that in c?
What is difference between followin intialization.int iVar1;int iVar2 = int();and which one of two should we prefer always and why?
Are private class-level variables inherited?
Are there any new intrinsic (built-in) data types?
I was trying to use an "out int" parameter in one of my functions. How should I declare the variable that I am passing to it?
When you inherit a protected class-level variable, who is it available to?
What is a node class in c++?
What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator.
Explain about Variables Data Types ?
Explain about Fundamental data types ?
Explain about Declaration of variables ?