Regular C/C++ Knowledge Flashcards
When should you use a pointer in C/C++ program?
- Any time you share, acces or modify data other than local variables in C/C++, you are going to need to use a pointer.
- In scenarios where you wish to pass a large chunk of memory through a function argument.
- You do not know the address of a memory while compiling the program.
- You would like to change a variable across files and one good practice is to send that variable as a pointer and get modified in called function.
- When you have to write a specific address like in embedded controllers such as 8051 or ARM Micro Controllers.
- Callback Functions
- Linked lists, where the devices are getting attached and removed at run time (USB Devices to a Laptop/Desktop).
- You want to access one data type in another data type format. Example: You have 256 Bytes of memory, but would like to process 4 Bytes at a time while computation time.
What is the difference between Static and Dynamic Memory Allocation in C?
Static Memory Allocation is a space in memory already created by the compiler in advance for variables that will be used, and Dynamic Memory Allocation is a way where memory can be allocated for variables during the run-time inside of the program.
What is Recursion?
The process in which a function calls itself directly or indirectly.
What is Stack Overflow error?
It is when the program tries to utilize more space than available when running a program and typically results in crashes.
What are some disadvantages of recursive programming as oppose to iterative programming?
Recursive programming has greater space and time requirements than iterative programming since all of the functions will remain in the stack until the base case is reached and the time it takes for the function calls and returns.
What are some advantages of recursive programming as oppose to iterative programming?
Recursion provides a clean and simple way to write code. Some problems are inherently recursive like tree traversals, which are preferred to write recursive code.
How many bytes does an “int” take up?
4 bytes of memory space and ranges from “-2147483648 to 2147483647”
How many bytes does a “char” take up?
1 byte of memory space and ranges from “-128 to 127” or “0 to 255”
How many bytes does a “boolean” take up?
1 byte of memory space
How many bytes does a “float” take up?
4 bytes of memory space
How many bytes does a “double float” take up?
8 bytes of memory space
How many bytes does a “short int” take up?
2 bytes of memory and ranges from “-32,768 to 32,767”
How many bytes does a “unsigned short int” take up?
2 bytes of memory and ranges from “0 to 65,535”
How many bytes does a “unsigned int” take up?
4 bytes of memory space and ranges from “0 to 4,294,967,295”
How many bytes does a “long int” take up?
8 bytes of memory space and ranges from “-2,147,483,648 to 2,147,483,647”
How many bytes does a “unsigned long int” take up?
8 bytes of memory space and ranges from “0 to 4,294,967,295”
How many bytes does a “long long int” take up?
8 bytes of memory space and ranges from “-(2^63) to (2^63)-1”