This commit is contained in:
Ajay T Shaju
2023-09-18 22:30:58 +05:30
parent 1c94e54c7c
commit 8e3299d2df
2 changed files with 191 additions and 145 deletions

View File

@@ -1,119 +1,4 @@
32 Reserved words
Term Description
auto optional local declaration
break used to exit loop and used to exit switch
case choice in a switch
char basic declaration of a type character
const prefix declaration meaning variable can not be changed
continue go to bottom of loop in for, while and do loops
default optional last case of a switch
do executable statement, do-while loop
double basic declaration double precision floating point
else executable statement, part of "if" structure
enum basic declaration of enumeration type
extern prefix declaration meaning variable is defined externally
float basic declaration of floating point
for executable statement, for loop
goto jump within function to a label
if executable statement
int basic declaration of integer
long prefix declaration applying to many types
register prefix declaration meaning keep variable in register
return executable statement with or without a value
short prefix declaration applying to many types
signed prefix declaration applying to some types
sizeof operator applying to variables and types, gives size in bytes
static prefix declaration to make local variable static
struct declaration of a structure, like a record
switch executable statement for cases
typedef creates a new type name for an existing type
union declaration of variables that are in the same memory locations
unsigned prefix declaration applying to some types
void declaration of a typeless variable
volatile prefix declaration meaning the variable can be changed at any time
while executable statement, while loop or do-while loop
Basic types
Type Description
char character type, usually one byte ( a string is array of char )
int integer type, usually 2 or 4 bytes ( default )
float floating point type, usually 4 bytes
double floating point type, usually 8 bytes
void no type, typeless
enum enumeration type ( user defines the type name )
Type modifiers, prefix for basic types
Modifiers Description
signed has a sign ( default )
unsigned no sign bit in variable
long longer version of type (short or long alone means short int or
short shorter version of type long int because int is the default)
const variable can not be stored into
Storage Types
Prefix Description
auto local variable ( default )
static permanent when function exits, not auto
volatile can change from outside influence
extern variables are defined elsewhere, externally
register assign variable to register
Operators
( ) grouping parenthesis, function call
[ ] array indexing, also [ ][ ] etc.
-> selector, structure pointer
. select structure element
! relational not, complement, ! a yields true or false
~ bitwise not, ones complement, ~ a
++ increment, pre or post to a variable
-- decrement, pre or post to a variable
- unary minus, - a
+ unary plus, + a
* indirect, the value of a pointer, * p is value at pointer p address
& the memory address, & b is the memory address of variable b
sizeof size in bytes, sizeof a or sizeof (int)
(type) a cast, explicit type conversion, (float) i, (*fun)(a,b), (int*)x
* multiply, a * b
/ divide, a / b
% modulo, a % b
+ add, a + b
- subtract, a - b
<< shift left, left operand is shifted left by right operand bits
>> shift right, left operand is shifted right by right operand bits
< less than, result is true or false, a %lt; b
<= less than or equal, result is true or false, a <= b
> greater than, result is true or false, a > b
>= greater than or equal, result is true or false, a >= b
== equal, result is true or false, a == b
!= not equal, result is true or false, a != b
& bitwise and, a & b
^ bitwise exclusive or, a ^ b
| bitwise or, a | b
&& relational and, result is true or false, a < b && c >= d
|| relational or, result is true or false, a < b || c >= d
? exp1 ? exp2 : exp3 result is exp2 if exp1 != 0, else result is exp3
= store
+= add and store
-= subtract and store
*= multiply and store
/= divide and store
%= modulo and store
<<= shift left and store
>>= shift right and store
&= bitwise and and store
^= bitwise exclusive or and store
|= bitwise or and store
, separator as in ( y=x,z=++x )
Operator precedence
More precedence
@@ -136,30 +21,6 @@ LR ,
Less precedence
Conditional branching
if ( condition ) statement ;
else statement_2 ; /* optional else clause */
Switch statement
switch ( expression ) /* constants must be unique */
{
case constant_1: /* do nothing for this case */
break;
case constant_2: /* drop through and do same as constant_3*/
case constant_3:
statement_sequence /* can have but does not need { } */
break;
case constant_4:
statement_sequence /* does this and next */
/* statement_sequence also*/
case constant_5:
statement_sequence
break;
default: /* default executes if no constant equals*/
statement_sequence /* the expression. This is optional */
}
Function definition