There is a list of all operators in C.
- Assignment Operator
- Arithmetic Operators
- Cast Operator
- Increment and Decrement Operators
- Abbreviated Assignment Operators
- Relational Operators
- Logical Operators
- Precedence of Operators
I. Assignment Operator
Equal sign (=) is used as assignment operator in C and it must be read as “is assigned the value of”.
That means: a is assigned value of b. There is also this usage that allows you to make multiple assignments like this:
All of the variables are equalized to 153. The precedence of assignment operator is right to left. That means first o is equalized to 153, then c is assigned value of o which is 153, finally r is assigned value of c. Click to Read Complete Article »
Generating random numbers is very important in programming. It’s difficult as much as it’s important. Actually, there is nothing random. A number, which is choosen according to some criterias (mostly time), is used in some functions, then a random number is given (for us) by those functions…
Let’s start.
Structure 1.1: We will need three libraries. (stdio.h,stdlib.h and time.h)
1 2 3 4 5 6 7 8
| #include <stdio.h>
#include <stdlib.h>
#include <time.h>
main(){
srand((unsigned)time(0)); /* this function is used to generate a different number for each time we call rand() function */
rand() % MaxNum; /* The MaxNum is our maximum limit. */
} |
Formula: 0 <= result < MaxNum
Example 1.1: This using gives us a random number between 0(included) and 100(excepted).
1 2 3 4 5 6 7 8 9
| #include <stdio.h>
#include <stdlib.h>
#include <time.h>
main(){
srand((unsigned)time(0));
printf("The generated random number: %d",rand() % 100);
getch();
} |
getch() function is used to see the result before the command screen closed and only exist on dos based operating systems. We could use the system(”pause”) function instead of it.
Don’t forget! In the cyber world, there is not random. I think, in the real world is too…
There are three methods for making a loop with C. There is a list of all loop structures in C:
I. While loop
II. Do … While loop
III. For loop
I. While Loop
This statement can be very useful if you don’t have or don’t know number of repetitions because it loops the operations while specified conditions are true.
Structure 1.0 : Via this structure, the condition will be evaluated before the loop begin. If conditions are false then loop will be skipped else operations are executed then the conditions will be evaluated again. If conditions are still true then it will execute the operations again…
1 2 3 4 5
| while( conditions ){
...
operations
...
} |
There is a simple code example that shows us how to use Click to Read Complete Article »
Recently Typed