Variables are simply where you store data. A variable has a name and data type.
Data Types
| Different Data Types in C | |
|---|---|
| int | integer |
| char | character |
| float | floating point value; decimal |
| double | double precision floating point value |
I only listed the basic but this would be enough to make a simple program.
So yeah, basically data types exist so that the compiler will know what are you trying to store in a specific variable. Error will be raised when you try to store a character in an int variable.
Variable Declaration
Examples:
1 2 | int age; char gender; |
The value of the variables above is null after their declaration but you can also define a default value like:
1 2 3 4 5 6 7 8 9 10 | /* A variable to determine whether a game is already over. And of * course, it has to be false at the start of the game. * * By the way, this is the correct way of writing multiple-lined * comments in C and in many more programming languages. */ int isGameOver = 0; // I was kind of feminist, you know. char gender = 'F'; |
Previous Topic Course Outline Next Topic
No comments:
Post a Comment