Friday, September 27, 2013

Footnote of C

In C main components are its keywords, variable & const , functions etc.

  • This language have reserve keywords to indicate something. We cannot use these keywords to indicate anything else. 
  • Variable :- These are memory blocks to hold values. Each variable has a type. Variables are mutable i.e. change in the variable content will change the content of respective memory block.
  • Data type :- A data type represents a system to indicate the type of data, like size and its functionality. We have no class concept in C so in build in libraries the definition of basic data type like int, char, float etc are given. We can build our own data type using typedef, Structure, union and enum .   
  • Pointer :-  Pointer is a variable stores the l-value of another variable in the virtual memory. In C pointer has constant size but it also hold the the type of data it is pointing to. We can manipulate the values in the pointed location by a process called de-referencing.  
  • Constant is a variable with constant or fixed value. This be stored in static position in function activation, we will see later what is static position.
  • Array :- Consecutive memory blocks from same type where the array name is representing a pointer holding the 1st memory address of those blocks. Array are normally statically allocated allocated. They could be dynamically allocated by malloc, calloc, realloc. 
  • Structured Programming :- In C part of code inside a '{'  and corresponding '}' represents a block or bundle of code to be executed as a group.  A block represents a complex task  formed by sequence of simpler tasks. Ex. eating could be a block consist of -         
    • picking up food by hand, put it in mouth,    
    • chew in mouth and pass the food  to digestion system, 
    • if  still fill hungry and there is more food  then                                                                           go to the step 1.
    C implements block as simply some lines in '{}' or a loop or a function or structure,union, enum etc.
  • Pre-process :- C facilitates pre-process using command after '#' directive. In pre-process it defines some strings as something, includes files/headers, check by #ifndef or #ifdef and #endif pairs etc.
  • Function  :- C use system stack to implement recursion of repeating code segments. Functions in C is like mathematical functions which take some input and generates some output. We supply some variable's value to the function (Call by value) and it give output to the calling function or manipulate some memory places used/generated by that program or manipulates std streams/files (stdin,stdout,stderr) or some other file in memory.  
  • Function Pointer :- In C a function pointer points to the executable code of a function in memory. We can call the function by the function pointer.
  • Function Call :- A function is been called by de-referencing its function pointer. Unlike copy-rule of sub-routine here we create an Activation Record holding current values in all local and temporary variables  ( while constant and static as well as global variables  and function's executable codes will be in Static Storage ). Each activation record will have a Current Instruction pointer to the next instruction of the calling function and Current Environment pointer to the calling activation.
  • Procedural Code :-  C normally read and execute the program file from the top to bottom ( This is called execution path or control flow direction ). The execution start from 'main' function. From there multiple functions are called in execution path. The function call take the control the called function's executable code. 
  • Memory Management :- C normally split the virtual memory mainly in Static, Heap and Stack and Un-allocated zone. The heap and stack are taking their requirement from the Un-allocated zone from both side of it.
    Stack consist of data of Activation Records. Heap has dynamic memory allocated blocks.
  • Scope and Lifetime :- A variable or functions scope is the span of code up to which it can be accessed [ That is if the control is in the scope of some variable it could be accessed by the control ]. A variable's life time is the range of code till which the variable will hold a position in memory. Nb. A dead variable cannot have scope but the reverse is possible. [1] .

No comments:

Post a Comment