2.1 - Key Words Types
Keywords – Qualifiers
- const
It specifies the value of a field or a local variable that cannot be modified.
- volatile
- Instructs the compiler not to optimise the variable qualified with it
- Indicates that the variable is asynchronous, and system or external sources may change its value
Keywords – Loops
- for
- Could be used when the number of passes is known in advance (but not necessarily)
- while
- Could be used when the number of passes is not known in advance (but not necessarily)
- Entry controlled looping mechanism
- do
- Could be used when the number of passes is not known in advance (but not necessarily)
- Exit controlled looping mechanism
Keywords – Storage Class
auto - Storage: Memory
- Default Initial Value: Unpredictable
- Scope: Local
- Life: Within the Block
register - Storage: CPU Register's
- Default Initial Value: Garbage
- Scope: Local
- Life: Within the Block
static - Storage: Memory
- Default Initial Value: Zero
- Scope: Local
- Life: Across Function Calls
- Other's: Limits the Function scope to the current file.
extern - Storage: Memory
- Default Initial Value: Zero
- scope: Global
- Life: Program Life
Keywords – Decision
- if
- Simple conditional branching statement
- Any non-zero value is treated as a true value and will lead to execution of this statement
- else
- Used with if statements
- Else part is executed when the condition in if becomes false
- switch
- A specialised version of an if-else cascade
- Equality checks only with integral type constants
- Simplified control-flow by generating much faster code
- Break keyword is must to end the current case
- case
- Used in switch statements for selecting a particular case
- The case should be followed by a constant integral expression.
- default
- This label is used in switch statements
- The statements after this label will be executed only when there is no match found in the case labels.
Keyword - Jump
- goto
- Take the control to required place in the program
- break
- Force immediate termination of a loop, bypassing the conditional expression and any remaining code in the body of the loop
- continue
- Take the control to the beginning of the loop bypassing the statements inside the loop
Keywords – Derived types
- struct
- struct keyword provides support for aggregate types
- unions
- Can be considered a special case of structures
- The syntax for both is mostly the same and only the semantics differ
- Memory is allocated such that it can accommodate the biggest member
- There is no in-built mechanism to know which union member is currently used to store the value
Keywords – User Defined
- typedef
- Do not create new types - they just add new type names
- Helpful in managing complex declarations
- Increase portability of the code
- Obey scoping rules and are not textual replacements (as opposed to #defines)
- enum
- A set of named constants that are internally represented as integers
- Makes the code more readable and self-documenting
Keywords – Others
- void
- Non-existent or empty set of values
- It is used in the case of void pointers as a generic pointer type in C
- Return type of a function to specify that the function returns nothing
- You cannot have objects of type void, and hence this type is sometimes called a pseudo-type.
- return
- To return control back from the called method
- sizeof
- Used to obtain the size of a type or an object
- Can be used for portable code, since the size of a data type may differ depending on the implementation.
...
Post a Comment