Friday, 15 December 2017

Days to Learn Advance C language, In debth C questions and answers




Day 1:


  1. Compilation :
                Find the compilation steps from .c format to executable format.
                Collect the files which was generated in each steps
                Analysis the file and understand the purpose of each file.


Day 2:


  1. What are all storage class is available in c,  the scope (visibility) and life-time of variables and/or functions within a C Program.
  2. Difference between static function & normal function.  With example programs.


Day 3:


  1. Memory Layout of C Programs ?
    1. Check the size of text, data, and bss segments of below programs.
      1. Check the following simple C program
                                                           #include <stdio.h>
                                               int main(void)
                                                          {
                                                                return 0;
                                                           }


    1.   Let us add one global variable in program, now check the size of bss (highlighted in red color)
                                                         #include <stdio.h>
                                              int global; /* Uninitialized variable stored in bss*/
                                              int main(void)
                                                         {
                                                             return 0;
                                                         }


  1. Let us add one static variable which is also stored in bss.
                                                        #include <stdio.h>
                                             int global; /* Uninitialized variable stored in bss*/
                                             int main(void)
                                                       {
                                                            static int i; /* Uninitialized static variable stored in bss */
                                                            return 0;
                                                        }

  1. Let us initialize the static variable which will then be stored in Data Segment (DS)
                                            #include <stdio.h>
                                            int global; /* Uninitialized variable stored in bss*/
                                            int main(void)
                                                      {
                                                           static int i = 100; /* Initialized static variable stored in DS*/
                                                           return 0;
                                                       }

  1.  Let us initialize the global variable which will then be stored in Data Segment (DS)
                                                       #include <stdio.h>
                                            int global = 10; /* initialized global variable stored in DS*/
                                            int main(void)
                                                       {
                                                           static int i = 100; /* Initialized static variable stored in DS*/
                                                           return 0;
                                                       }

Day 4:

  1. Read below to understand the heap memory:
    1. What is heap memory?
    2. Difference between malloc(), calloc() & realloc()
    3. What is Memory Leak? How can we avoid?
      1. Answer: Memory Leak
    4. what is the difference between memory leak & memory wastage
      1. Answer: Memroy Leak vs Memory wastage
    5. Why need to use free() ?
    6. what is heap corruption in c ?

No comments:

Post a Comment