Learnings of the week
By: Sharra Mae S. Tagaro IV- Rizal
- Avoid using names that are too short or too long.
- Limit the identifiers from 8 to 15 characters only.
Rules for defining or naming identifiers
- It must consist only of letters, digits, and underscore.
- Example: _duh, num_1 (correct)
- It should not begin with a digit.
- Example: 1name, 3to3 (incorrect)
- An identifier defined in the C standard library should not be redefined.
- Example: printf, scanf (incorrect)
- It is case sensitive; meaning uppercase is not equal to the lowercase.
- Example: ans != Ans != aNs
- Do not include embedded blanks.
- Example: large num (incorrect)
- Do not use any of the C language keywords as your variable/ identifier.
- Do not call your variable / identifier by the same name as other functions.
Variable Declaration
- All variables must be declared before they may be used. The general form of declaration is shown here:
Type variable list;
Example: int i,j, k;
short i,j,k;
- Note: Before declaring variables, specify first the data type of the variable/s.
- Variables must be separated by comma.
- All declarations must be terminated by a semicolon (;).
Two kinds of variables
- Local Variables - Variables that are declared inside a function are called local variables. It can only be referenced by statements that are inside the block in which the variables are declared.
- Global Variables - Global variables are known throughout the entire program and may be used by any piece of code. Global variables are created by declaring them outside of any function.
- Constants are identifier / variables that can store a value that cannot be changed during program execution.
- Example: const int count = 100;
- Where integer count has a fixed value of 100.
Arithmetic, Logical, Relational, and Bitwise Operations
- Operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
- There are three classes of operators in C: arithmetic, logical and relational, and bitwise.
Arithmetic Operators
Operator Action
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus Divisor
-- Decrement a value
++ Increment a value
Relational and Logical Operators
- In the term relational operator, the word relational refers to the relationship values can have with one another.
- In the term logical operator, the word logical refers to the ways these relationships can be connected together using the rules of formal logic.
Relational Operators
Operators Action
> Greater than
>= Greater than or equal to
<>
<= Less than or equal to
== equal
!= Not equal
Logical Operators
Operators Action Truth Table
&& AND true && true = true
true && false = false
false && true = false
false && false = false
OR true true = true
true false = true
false true = true
false false = false
! NOT !true = false
!false = true
Bitwise Operator
- Bitwise operators are the testing, setting or shifting of the actual bits in a byte or a word, which corresponds to C’s standard char and int data types and variants.
- Bitwise operators cannot by used on type float, double, long double, void or other more complex types.
The ? Operator
? Operator is a very powerful and convenient operator that can be used to replace certain statements of the if-then-else form.
- Example: y= x > 9 ? 100: 200
is equivalent to
If (x>9)
y=100;
Else
Y=200;
Evaluation of Expression
- Expression refers to anything that evaluates to a numeric value.
Order of Precedence
()
!, unary +, -
*. /. %
binary + , -
<, <=, >, >=
==, !=
&&
By: Sharra Mae S. Tagaro IV- Rizal
VARIABLES, CONSTANTS, OPERATORS AND EXPRESSION
- Identifiers are composed of a sequence of letters. Digits, and the special character _ (underscore).- Avoid using names that are too short or too long.
- Limit the identifiers from 8 to 15 characters only.
Rules for defining or naming identifiers
- It must consist only of letters, digits, and underscore.
- Example: _duh, num_1 (correct)
- It should not begin with a digit.
- Example: 1name, 3to3 (incorrect)
- An identifier defined in the C standard library should not be redefined.
- Example: printf, scanf (incorrect)
- It is case sensitive; meaning uppercase is not equal to the lowercase.
- Example: ans != Ans != aNs
- Do not include embedded blanks.
- Example: large num (incorrect)
- Do not use any of the C language keywords as your variable/ identifier.
- Do not call your variable / identifier by the same name as other functions.
Variable Declaration
- All variables must be declared before they may be used. The general form of declaration is shown here:
Type variable list;
Example: int i,j, k;
short i,j,k;
- Note: Before declaring variables, specify first the data type of the variable/s.
- Variables must be separated by comma.
- All declarations must be terminated by a semicolon (;).
Two kinds of variables
- Local Variables - Variables that are declared inside a function are called local variables. It can only be referenced by statements that are inside the block in which the variables are declared.
- Global Variables - Global variables are known throughout the entire program and may be used by any piece of code. Global variables are created by declaring them outside of any function.
- Constants are identifier / variables that can store a value that cannot be changed during program execution.
- Example: const int count = 100;
- Where integer count has a fixed value of 100.
Arithmetic, Logical, Relational, and Bitwise Operations
- Operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
- There are three classes of operators in C: arithmetic, logical and relational, and bitwise.
Arithmetic Operators
Operator Action
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus Divisor
-- Decrement a value
++ Increment a value
Relational and Logical Operators
- In the term relational operator, the word relational refers to the relationship values can have with one another.
- In the term logical operator, the word logical refers to the ways these relationships can be connected together using the rules of formal logic.
Relational Operators
Operators Action
> Greater than
>= Greater than or equal to
<>
<= Less than or equal to
== equal
!= Not equal
Logical Operators
Operators Action Truth Table
&& AND true && true = true
true && false = false
false && true = false
false && false = false
OR true true = true
true false = true
false true = true
false false = false
! NOT !true = false
!false = true
Bitwise Operator
- Bitwise operators are the testing, setting or shifting of the actual bits in a byte or a word, which corresponds to C’s standard char and int data types and variants.
- Bitwise operators cannot by used on type float, double, long double, void or other more complex types.
The ? Operator
? Operator is a very powerful and convenient operator that can be used to replace certain statements of the if-then-else form.
- Example: y= x > 9 ? 100: 200
is equivalent to
If (x>9)
y=100;
Else
Y=200;
Evaluation of Expression
- Expression refers to anything that evaluates to a numeric value.
Order of Precedence
()
!, unary +, -
*. /. %
binary + , -
<, <=, >, >=
==, !=
&&
No comments:
Post a Comment