|
|
(46 intermediate revisions by 5 users not shown) |
Line 6: |
Line 6: |
| * [[Meaning of Static | What is a '''static''' keyword in C/C++?]] | | * [[Meaning of Static | What is a '''static''' keyword in C/C++?]] |
| * [[Interview Preparation Linked List | Linked List]] | | * [[Interview Preparation Linked List | Linked List]] |
− | * [[Interview Preparation topic by Shantanu_Vashishtha: Linked List | Linked List]] | + | * [[Interview Preparation topic : About '''extern''' keyword in C/C++ | About '''extern''' keyword in C/C++]] |
− | | + | * [[Interview Preparation topic : Pointers in C | Pointers in C]] |
| + | * [[Interview Preparation topic : Structures and Unions | Structures and Unions]] |
| + | * [[Inline Specifier | '''Inline''' Specifier]] |
| + | * [[Dynamic memory allocation in C]] |
| + | * [[Standard Predefined Macros]] |
| + | * [[Interview Preparation topic: Recursive Function | Recursive Function]] |
| + | * [[Interview Preparation topic: Name Mangling | Name Mangling]] |
| <br/> | | <br/> |
| | | |
| == C++ Object Oriented Topics == | | == C++ Object Oriented Topics == |
| * [[Interview Preparation C++ Virtual, Polymorphism and Abstract class |What is "virtual", "polymorphism" and "abstract class"?]] | | * [[Interview Preparation C++ Virtual, Polymorphism and Abstract class |What is "virtual", "polymorphism" and "abstract class"?]] |
| + | * [[Dynamic Memory Allocation in C++]] |
| | | |
| <br/> | | <br/> |
| + | |
| == Operating Systems Topics == | | == Operating Systems Topics == |
| === FreeRTOS Tutorial === | | === FreeRTOS Tutorial === |
Line 21: |
Line 29: |
| === Other OS Topics === | | === Other OS Topics === |
| * [[Interview Preparation OS Synchronization Primitives|Synchronization Primitives - Mutexes, Spinlocks, Queues etc.]] | | * [[Interview Preparation OS Synchronization Primitives|Synchronization Primitives - Mutexes, Spinlocks, Queues etc.]] |
− | * [[Interview Preparation OS Common Problems|Common Problems in Multitasking OS]] | + | * [[Kernel Space and User Space|Kernel Space and User Space]] |
| | | |
| <br/> | | <br/> |
| + | |
| == Miscellaneous Topics == | | == Miscellaneous Topics == |
| === Bit Fiddling === | | === Bit Fiddling === |
Line 30: |
Line 39: |
| * [[Bit Structures | Bit Structures and Unions]] | | * [[Bit Structures | Bit Structures and Unions]] |
| === BSS and Data Segments === | | === BSS and Data Segments === |
− | | + | * [[Where do your variables stored | Where are Global and static variables stored ?]] |
− | <pre>
| + | <br/> |
− | What are text,.bss and data sections in an Embedded C program?
| |
− | | |
− | Where do your program recide?Obviously memory,but how is it organized? | |
− | In embedded systems ,which are RAM-memory constrained ,memory map is divided into segments
| |
− | called text,data and bss.
| |
− |
| |
− | Text segment:Contains code and constants of the program.Text section is allocated on flash.
| |
− | Eg1: a.out :executable code
| |
− | Eg2:const uint8_t i=8 :contant
| |
− | Eg3:
| |
− |
| |
− | #include <stdio.h>
| |
− | const int global_var=20;
| |
− | int data_variable = 500;
| |
− | static int static_var=10;
| |
− | void foo(){
| |
− | const int local_constant=100;
| |
− | int local;
| |
− | local = 3;
| |
− | int un_initialized;
| |
− | int another_initialized=0;
| |
− | static int local_static=9;
| |
− | local_static++;
| |
− | printf("local varaible is %d\n", local);
| |
− | }
| |
− |
| |
− | In the above example, executable code of the program is stored in flash and const variable global_var=20 and local_constant=100 are stored in flash.
| |
− |
| |
− | Data segment:Initialized variables are stored in this section.
| |
− | Initially values are stored in flash and copied into RAM during execution
| |
− | through copy down process.
| |
− |
| |
− | Eg: uint8_t j=10; initialized variable
| |
− |
| |
− | In the code given above int data_variable = 500,static int static_var=10,local = 3, and local_static=9 are stored in data segment of flash.
| |
− |
| |
− | .bss segment:Uninitialized variables are stored in bss section.
| |
− |
| |
− | In embedded software, the bss segment is mapped into memory that is initialized to zero by the C run-time system before main() is entered.
| |
− | (wiki :https://en.wikipedia.org/wiki/.bss#BSS_in_C)
| |
− |
| |
− | Eg:int newvar;
| |
− |
| |
− | In the above code un_initialized(after initializing it to zero) and another_initialized are stored in bss section ;
| |
− |
| |
− | Simple example:
| |
− | | |
− | #include <stdio.h>
| |
− | int main(void)
| |
− | {
| |
− | return 0;
| |
− | }
| |
− | Memory occupied by the above program:
| |
− |
| |
− | $ gcc -o just_main just_main.c
| |
− | $ size just_main.exe
| |
− | text data bss dec hex filename
| |
− | 3153 1976 448 5577 15c9 just_main.exe
| |
− | After modifying the above program with one global variable:
| |
− |
| |
− | #include <stdio.h>
| |
− | int global_var;
| |
− | int main(void)
| |
− | {
| |
− | return 0;
| |
− | }
| |
− |
| |
− | $ gcc -o just_main just_main.c
| |
− | $ size just_main.exe
| |
− | text data bss dec hex filename
| |
− | 3153 1976 464 5593 15d9 just_main.exe
| |
− | bss section is increased by 2 bytes;
| |
− |
| |
− | Modify the above program with global variable initialized to zero;
| |
− |
| |
− | #include <stdio.h>
| |
− | int global_var=0;
| |
− | int main(void)
| |
− | {
| |
− | return 0;
| |
− | }
| |
− |
| |
− | $ gcc -o just_main just_main.c
| |
− | $ size just_main.exe
| |
− | text data bss dec hex filename
| |
− | 3153 1976 480 5609 15e9 just_main.exe
| |
− | bss segment is increased by 32 bits(4 bytes)
| |
− |
| |
− | Modify the above program with global variable initialized to non-zero;
| |
− |
| |
− | #include <stdio.h>
| |
− | int global_var=8;
| |
− | int main(void)
| |
− | {
| |
− | return 0;
| |
− | }
| |
− | $ gcc -o just_main just_main
| |
− | $ size just_main.exe
| |
− | text data bss dec hex filename
| |
− | 3153 1976 448 5577 15c9 just_main.exe
| |
− | bss section is not modified.
| |
− |
| |
− |
| |
− | FAQ:
| |
− | What is the size of bss segment?
| |
− | bss does not take any space in the object file and stores the count of variables that can be given initial values.Hence occupy 4 or 8 bytes
| |
− | depending on the implementation.
| |
− |
| |
− | What is the amount of RAM being used?
| |
− | Memory occupied by bss and data segments added together.
| |
− |
| |
− | </pre> | |
| | | |
| === Others === | | === Others === |
| * [[Interview Preparation Strings |String Manipulation]] | | * [[Interview Preparation Strings |String Manipulation]] |
| * [[Interview Preparation Pointers|All about pointers]] | | * [[Interview Preparation Pointers|All about pointers]] |
− | | + | * [[Null Pointer]] |
| + | * [[Add without using any arithmetic operators]] |
| + | * [[Data Structure Alignment-Packing of Structures]] |
| + | * [[Priority Queues]] |
| + | * [[Integer promotion in C]] |
| <br/> | | <br/> |
| | | |
| == Sorting Topics == | | == Sorting Topics == |
− | Sorting means arrangement of elements in a defined manner(Ascending/Descending order). This is widely used in the complex algorithms to decrease the time complexity. There are six types of sorting algorithms namely, Bubble Sort, Insertion Sort, Merge Sort, Quick Sort, Heap Sort and Selection Sort.
| + | * [[Interview Preparation Sorting |Sorting]] |
− | | |
− | * [[Interview Preparation Bubble Sort | Bubble Sort]] | |
− | * [[Interview Preparation Insertion Sort | Insertion Sort]]
| |
− | * [[Interview Preparation Merge Sort | Merge Sort]]
| |
− | * [[Interview Preparation Quick Sort | Quick Sort]]
| |
− | | |
− | === Big O notation ===
| |
− | Big O notation is a mathematical way of representing an approximate time required for an expression to complete by checking for its major dependencies.
| |
− | For a example, f(n) = n^5 + n.
| |
− | | |
− | As we go on increasing the value of n the dependency on the second half equation on the right-hand side will reduce.
| |
− | | |
− | so, we can also say that f(n) = n^5 or complexity is O(n^5) for n equal to infinity.
| |
− | | |
− | Note: For comparison of big O complexity for different algorithms, refer following site: http://bigocheatsheet.com/
| |
− | | |
− | === Source Code ===
| |
− | * [https://gitlab.com/Khanna_Bharat/Data_Structure Gitlab Source Code Link]
| |
− | | |
− | | |
− | ==Searching Algorithms==
| |
− | Information retrieval is critical in any computer application. Large sets of records are stored in computer system, from which a particular record is fetched in which required information would be stored. Each record stored in the computer environment would have a key associated to it. Based on the search criteria system scans through the records and extract the matching records only. To Increase the speed or reduce the information retrieval duration, various searching techniques are used.
| |
| | | |
− | Below are the basic commonly used searching algorithms.
| + | == Algorithms== |
− | * [[Linear Search]] | + | *[[Searching Algorithms]] |
− | * [[Binary Search]] | + | *[[Graph Algorithms]] |
| | | |
| ==Embedded C Interview Questions and Answers== | | ==Embedded C Interview Questions and Answers== |
| | | |
− | ===1) What is the use of volatile keyword?===
| + | The following link would navigate to some questions that are very commonly asked in interviews(Cisco,Intacct,WNI etc.). It encloses some C programs as well. |
− | | |
− | The C's volatile keyword is a qualifier that tells the compiler not to optimize when applied to a variable. By declaring a variable volatile, we can tell the compiler that the value of the variable may change any moment from outside of the scope of the program. A variable should be declared volatile whenever its value could change unexpectedly and beyond the comprehension of the compiler. | |
− | | |
− | | |
− | ===2) Can a variable be both const and volatile?===
| |
− | | |
− | The const keyword make sure that the value of the variable declared as const can't be changed. This statement holds true in the scope of the program. The value can still be changed by outside intervention. So, the use of const with volatile keyword makes perfect sense.
| |
− | | |
− | | |
− | ===3) Can a pointer be volatile?===
| |
− | | |
− | If we see the declaration volatile int *p, it means that the pointer itself is not volatile and points to an integer that is volatile. This is to inform the compiler that pointer p is pointing to an integer and the value of that integer may change unexpectedly even if there is no code indicating so in the program.
| |
− | | |
− | | |
− | ===4) What is size of character, integer, integer pointer, character pointer?===
| |
− | | |
− | • The sizeof character is 1 byte.
| |
− | | |
− | • Size of integer is 4 bytes.
| |
− | | |
− | • Size of integer pointer and character is 8 bytes on 64 bit machine and 4 bytes on 32 bit machine.
| |
− | | |
− | ===6) What is void pointer and what is its use?===
| |
− | | |
− | The void pointer means that it points to a variable that can be of any type. Other pointers points to a specific type of variable while void pointer is a somewhat generic pointer and can be pointed to any data type, be it standard data type(int, char etc) or user define data type (structure, union etc.). We can pass any kind of pointer and reference it as a void pointer. But to dereference it, we have to type the void pointer to correct data type.
| |
− | | |
− | ===7) What is ISR?===
| |
− | | |
− | An ISR(Interrupt Service Routine) is an interrupt handler, a callback subroutine which is called when a interrupt is encountered.
| |
− | | |
− | | |
− | ===8) What is return type of ISR?===
| |
− | | |
− | ISR does not return anything. An ISR returns nothing because there is no caller in the code to read the returned values.
| |
− | | |
− | ===9) What is interrupt latency?===
| |
− | | |
− | Interrupt latency is the time required for an ISR responds to an interrupt.
| |
− | | |
− | ===10) How to reduce interrupt latency?===
| |
− | | |
− | Interrupt latency can be minimized by writing short ISR routine and by not delaying interrupts for more time.
| |
− | | |
− | ===Write a short code using C===
| |
− | | |
− | 1)Code to print out all odd number from 1 to 100 using a for loop
| |
− | | |
− | <pre>
| |
− | | |
− | for( unsigned int i = 1; i < = 100; i++ )
| |
− | | |
− | if( i & 0x00000001 )
| |
− | | |
− | printf(“i=%u”,&i);
| |
− | | |
− | </pre>
| |
− | | |
− | 2)Write out a function that prints out all the permutations of a string. For example, abc would give you abc, acb, bac, bca, cab, cba.
| |
− | | |
− | <pre>
| |
− | | |
− | // C program to print all permutations with duplicates allowed
| |
− | #include <stdio.h>
| |
− | #include <string.h>
| |
− |
| |
− | /* Function to swap values at two pointers */
| |
− | | |
− | void swap(char *x, char *y)
| |
− | | |
− | {
| |
− | char temp;
| |
− | temp = *x;
| |
− | *x = *y;
| |
− | *y = temp;
| |
− | }
| |
− |
| |
− | /* Function to print permutations of string
| |
− | This function takes three parameters:
| |
− | 1. String
| |
− | 2. Starting index of the string
| |
− | 3. Ending index of the string. */
| |
− | | |
− | void permute(char *a, int l, int r)
| |
− | {
| |
− | int i;
| |
− | if (l == r)
| |
− | printf("%s\n", a);
| |
− | else
| |
− | {
| |
− | for (i = l; i <= r; i++)
| |
− | {
| |
− | swap((a+l), (a+i));
| |
− | permute(a, l+1, r);
| |
− | swap((a+l), (a+i)); //backtrack
| |
− | }
| |
− | }
| |
− | }
| |
− |
| |
− | /* Driver program to test above functions */
| |
− | int main()
| |
− | {
| |
− | char str[] = "ABC";
| |
− | int n = strlen(str);
| |
− | permute(str, 0, n-1);
| |
− | return 0;
| |
− | }
| |
| | | |
− | </pre>
| + | * [[Interview Preparation Question and Answer]] |
Interview preparation requires proficient knowledge of C/C++. This article has just been recently written (July 2013) and will be elaborated soon; the articles in RED are waiting to be written. The hope is that this article will be "one-stop-shop" for most common C/C++ interview questions.
FreeRTOS is a real-time OS that has many ports for various different controllers. This is a great system to learn about because it gives you the fundamental knowledge of an operating system while making it incredibly easy to learn the material. Here's a must-read tutorial :
The following link would navigate to some questions that are very commonly asked in interviews(Cisco,Intacct,WNI etc.). It encloses some C programs as well.