Console Input/Output
|
Formatted Data |
|
Read value/s (type defined by format string) into variable/s (type must match) from the input stream. Stops reading at the first whitespace. &
prefix not required for arrays (including strings.) (unsafe) |
|
Prints data (formats defined by the format string) as a string to the output stream |
Alternative |
fgets(strName, length, stdin); sscanf();
|
Uses fgets to limit the input length, then uses sscanf to read the resulting string in place of scanf. (safe) |
Characters |
|
|
Returns a single character's ANSI code from the input stream buffer as an integer. (safe) |
|
Prints a single character from an ANSI code integer to the output stream buffer. |
Strings |
|
fgets(strName, length, stdin);
|
Reads a line from the input stream into a string variable. (Safe) |
|
Prints a string to the output stream. |
Data Types
Basic Data Type |
Floating-point, integer, double, character |
Derived Data Type |
Union, structure, array, etc |
Enumerated Data Type |
Enums |
Void Data Type |
Empty Value |
Boolean Type |
True or False |
Primary Data Types
Integer |
|
Storing Whole Numbers |
Character |
|
Refers to all ASCII character sets and single alphabets |
Long |
|
Long integer |
Floating point |
|
Refer to all the real number value or decimal point |
Double (Long float) |
|
Include all large type of numeric that do not come under floating point or integer |
Void |
|
No value |
Derived Data Types
Data Type |
Description |
Arrays |
A Sequence of a finite number of data items |
Function |
A self-contained block of single or multiple statements. |
Pointers |
Special form of variables for holding other variables’ addresses. |
Unions |
The memory that we allocate to the largest data type gets reused for all the other types present in the group. |
Structures |
A collection of various different types of data type items |
|
|
Standard Library Functions
|
|
Header File |
Description |
|
Standard input/output header file |
|
Console input/output header file |
|
String related functions are defined in this header file |
|
Contains general functions used in C |
|
All math related functions are defined here |
|
Contains time and clock related functions |
|
All character handling functions are defined here |
|
Variable argument functions are declared here |
|
Signal handling functions are declared here |
|
Includes all jump functions |
|
Includes locale functions |
|
Includes error handling functions |
|
Includes diagnostic functions |
Commenting
// |
Insert single-line comment |
example: |
//This is a single line comment
|
|
/* |
Insert multiple-line comment |
example: |
|
|
|
Conditional Statements
|
used to specify a block of code to be executed, if a specified condition is true |
|
used to specify a block of code to be executed, if the same condition is false |
|
used to to specify a new condition to test, if the first condition is false |
|
Used instead of writing many if...else
statements |
|
Used to stop the execution of more code and case testing inside the block |
Looping
|
Loops through a block of code as long as a specified condition is true |
|
This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true |
|
Loops through a block of code for a specified amount of repetitions |
|
Breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop |
|
Skips rest of loop contents and exits loop |
|
|
Control characters (Escape sequences)
|
Alert (bell) character |
|
Backspace |
|
Formfeed |
|
New line |
|
Carriage return |
|
Horizontal tab |
|
Vertical tab |
\\ |
Backslash |
|
Question mark |
|
Single quote |
|
Double quote |
|
null |
|
Any octal ANSI character code |
|
Any hexadecimal ANSI character code |
Arithmetic Operators
Operator |
Name |
Description |
|
Addition |
Adds together two values |
|
Subtraction |
Subtracts one value from another |
|
Multiplication |
Multiplies two values |
|
Division |
Divides one value by another |
|
Modulus |
Returns the division remainder |
|
Increment |
Increases the value of a variable by 1 |
|
Decrement |
Decreases the value of a variable by 1 |
compute
, calculate
, or add
statments can also be used |
Format Specifiers
|
Signed hexadecimal float |
|
A character |
|
Signed decimal integer |
|
Print as a decimal integer, at least 6 characters wide |
|
Signed decimal with scientific notation |
|
Signed decimal float |
|
Print as floating point, at least 6 characters wide |
|
Print as floating point, 2 characters after decimal point |
|
Print as floating point, at least 6 wide and 2 after decimal point |
|
Shortest representation of %f
or %e
|
|
Unsigned octal integer |
|
Character string |
|
Unsigned decimal integer |
|
Unsigned hexadecimal integer |
|
Display a pointer |
|
Print a % |
|
|
Primitive Variable Types
applicable but not limited to most ARM, AVR, x86 & x64 installations |
[class] [qualifier] [unsigned] type/void name; |
by ascending arithmetic conversion |
Integers |
Type |
Bytes |
Value Range |
|
1 |
|
|
1 |
0 to 255 |
|
1 |
-128 to 127 |
|
2 / 4 |
|
|
2 / 4 |
0 to 65,535 or 231-1 |
|
2 / 4 |
-32,768 to 32,767 or -231 to 232-1 |
|
2 |
|
|
2 |
0 to 65,535 |
|
2 |
-32,768 to 32,767 |
|
4 / 8 |
|
|
4 / 8 |
0 to 232-1 or 264-1 |
|
4 / 8 |
-231 to 231-1 or -263 to 263-1 |
|
8 |
|
|
8 |
0 to 264-1 |
|
8 |
-263to 263-1 |
// signed
is the default modifier of int
and char
data type (allows + or - value) |
// unsigned
only stores positive values |
Floats |
|
|
Type |
Bytes |
Value Range (Normalized) |
|
4 |
±1.2×10-38 to ±3.4×1038 |
|
8 / 4 |
±2.3×10 -308 to ±1.7×10 308 or alias to float
for AVR |
|
ARM: 8, AVR: 4, x86: 10, x64:16 |
Qualifiers |
|
|
|
Flags variable as read-only (compiler can optimise) |
|
Flags variable as unpredictable (compiler cannot optimise) |
Storage Classes |
|
|
|
Quick access required. May be stored in RAM or a register. Maximum size is register size. |
|
Retained when out of scope. static
global variables are confined to the scope of the compiled object file they were declared in. |
|
Variable is declared by another file |
Typecasting |
|
|
|
|
char x = 1, y = 2; float z = (float) x / y; |
Some types (denoted with or) are architecture dependant.
There is no primitive boolean type, only zero (false, 0
) and non-zero (true, usually 1
).
|