Local variables are the ones declared inside a function or a block (a block can be any number of statements inside if, for, switch or function). Local variables are not known outside where they are declared.
The global variables are declared before the main function and they are accessible from anywhere in the program. In other words, global variables are known to every function.
In C programming, we have:
In C programming, we have:
Logical operators are used to combine conditions and result is of Boolean type either true or false.
for loop is used when you know that how many times the loop has to be executed. while loop is used when the number of iterations are not known.
In while loop if the condition is false the control is not entered into the body of while loop. In do while loop the condition comes after the body of the loop so the body will be executed at least once.
Unary operators are the one that operates on one operand only for example increment and decrement operators to make an increment and decrement of one in the value of variable respectively.
In switch statement we have switch key word and a condition the result of which is compared with a number of cases. At the end we have default part which is executed when all cases are false:
continue statement skips the current iteration of the loop on the basis of a condition and break statement breaks the control making the control move outside the body of the loop on the basis of condition.
Both switch and if statements have multiple choices of which only one is executed. But in switch you cannot check range of values.
Ternary operator works with three operands. Ternary operator is a decision making construct. The first operand in ternary is the condition. If the condition is true second operand is executed else third operand is executed. Instead of if else, ternary operator can also be used.
An auto variable is a local variable. When you declare a variable as automatic it will be allocated memory at the beginning of the execution of the program and memory will be de allocated when the execution is done.
Storage classes specify how the variables will be stored in memory and where the variables are known in the program (scope of variables). Storage classes in C are:
An auto variable is a regular variable which is allocated memory when it is created and memory is de allocated when execution of program ends so this variable is destroyed. On the other hand a register keyword is used to create a register variable which will be stored in register in RAM. Register variables are fast and are accessed directly by the compiler.
When you create a static variable, the value of this variable will remain constant throughout the program. These variables are defined at the beginning of the program. Static variables cannot be destroyed.
Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer & technology lovers. http://www.techstudy.org/.