Syntax and Variables
Syntax:
One of the slightly frustrating elements of C is its formatting requirements (this also makes it very powerful). If you remember the following you should be alright.
// single line comment:
It is often useful to write notes to yourself as you go along about what each line of code does. To do this type two forward slashes and everything until the end of the line will be ignored by your program.
{} (curly brackets) :
Used to define when a block of code starts and ends (used in functions as well as loops).
/**/ Multi-line comment:
If you have a lot to say you can span several lines as a comment. Everything between these two symbols will be ignored in your program.
;(semicolon):
Each line of code must be ended with a semicolon (a missing semicolon is often the reason for a program refusing to compile).
VARIABLES
A program is nothing more than instructions to move numbers around in an intelligent way. Variables are used to do the moving.
boolean:
A simple True or False variable. Useful because it only uses one bit of RAM.
int (integer):
The main workhorse, stores a number in 2 bytes (16 bits). Has no decimal places and will store a value between -32,768 and 32,767.
float:
Used for floating point math (decimals). Takes 4 bytes (32 bits) of RAM and has a range between -3.4028235E+38 and 3.4028235E+38.
Long:
Used when an integer is not large enough. Takes 4 bytes (32 bits) of RAM and has a range between -2,147,483,648 and 2,147,483,647.
char (character):
Stores one character using the ASCII code (ie 'A' = 65). Uses one byte (8 bits) of RAM. The Arduino handles strings as an array of char's.
Vedant can we use these variables in javascript
ReplyDelete