Wednesday, January 31, 2018

Keywords in C

Definition

In each language, there is a bunch of words that can't be used by the user. These words are reserved words and are not available for redefinition or overloading. Now, here is a list of the reserved words in C.



As you can see, there are 32 different keywords in C programming language. But what are they used to?

Keywords Description

auto: this keyword isn't that important; variables declared within the functions are automatic by default. In this case, they are reserved each time the function is called.


break: this keyword is usually used to jump out of any kind of loops (for, while, do-while,switch).

case: switch, case and default come with each other. switch command is used to take the value of the variable inside of it, and enter the case depending on it. For example:
switch (c){
   case 1: ... break;
   case 2: ... break;
   default:...
} In this example if the input value of c is 1 the cursor will directly enter case 1, perform the tasks and go out of the switch statement cause by break keyword. If the value was 2, the cursor go inside case 2 and then breaks out. Now in the last step, if the input value doesn't match any of the cases the cursor will step inside default, execute what inside and go out of switch.

char, int, floatdouble are data types used for the same order: character type variable, integer variable, decimal number with single precision, and decimal number with double precision floating number.

const: this keyword is used to declare a constant variable (a variable where the value don't change).

continue: it's used to skip certain statement inside the loop.

for, while, do-while are different types of loops. When I say loop, it means that they are used to do the same process many times.

if, else: are both used for conditions: if the condition meets the requirement inside () after if the cursor enters it. If not, the cursor will directly move inside the else block.

enum: is used to declare many variable with the same type.

extern: is used to indicate that a variable or function are defined elsewhere, usually in a separate source code module.

goto: this keyword is used to transfer the cursor from a place to another.

short, long, signed, unsigned: are types modifier to alter the meaning of a base type to a new type.


register: this will store the variable directly in a CPU register.

return: this keyword is used to go out of a function, especially in some special cases where you don't need to continue the function.

sizeof: it gives the value of a variable in bytes.

static: this will help the variable's value to be changed even outside the scope of a function.

struct: this keyword is used to create a new data type that contains different types of data. The variable name after the struct will become the new data type where the attributes inside can be easily accessed using point.

typedef: is used to explicitly associate a type with an identifier. 

union: work the same as struct but all the types inside of it will occupy the same location in memory.

volatile: it's used for the variables that can be changed anytime. It's the opposite of const. In this case, the compiler will always read from memory.

If will try to cover as much as possible all the keywords in C programs in my next blogs so it becomes easier to understand.

You can also find some programs examples inside this book: http://amzn.to/2Fu2Bvc 



No comments:

Post a Comment