Storage classes
Volatile keyword
Register keyword
Static variable
Swap two variables without using a temp variable
a = 5
b = 3
a = (a+b);
a=8
b = a-b;
b=5;
a= a-b;
Can a variable be const and volatile
Yes. The const modifier implies that this particular program code cannot change the value of the actual variable, but that will not imply that the value can not be changed by means outside this code by hardware
Difference between calloc and malloc
Difference between exit and return
- Automatic
- Static
- Allocated
Volatile keyword
- Prevents CPU optimizing the variable
- Not atomic
- Eg: variable pointing to hardware register, system time
Register keyword
- Normal memory access can be slow compared to cpu access.
- Compiler can decide what var to be stored in register at what time
- Variable are kept in register - those that needs to be accessed often or access time is critical
- Variable defined outside any function block
- Defining - allocates memory for the variable
- Declare - requires the variable be defined already in the memory
Static variable
- Scope same as auto variable
- Storage is kept permanent as long as the program is running
- If defined in header file, each source file including it will have its own copy of the variable
Swap two variables without using a temp variable
a = 5
b = 3
a = (a+b);
a=8
b = a-b;
b=5;
a= a-b;
Can a variable be const and volatile
Yes. The const modifier implies that this particular program code cannot change the value of the actual variable, but that will not imply that the value can not be changed by means outside this code by hardware
Difference between calloc and malloc
- Calloc allocates block of memory each of certain size and inits it to 0.
- Malloc allocates certain bytes of memory
Difference between exit and return
- Return - returns call to the calling function
- Exit - exit out of the program and return control to the operating system
No comments:
Post a Comment