Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Objective-C Basics (Retired) Fundamentals of C Variables


I need to create a float variable

Kevin Lozandier
Kevin Lozandier
Courses Plus Student 53,747 Points

Since float is an existing type of value in C, you should be able to create a new float variable merely using float to prefix the variable name and the value you want:

float my_float_value = 2.0; 

3 Answers

The way you declare a variable in C is <type><name> = value. You can omit the value and add it later. So to declare this variable you should write float followed by the name of the variable. For example: float a;

thank you

float myfloatvalue =2.0; or float myfloatvalue; myfloatvalue=2.0;