Pointers & Memory Allocation notes PDF

Summary

These notes detail concepts like pointers, memory allocation, and demonstrate their implementation using C++. It provides various examples in the language.

Full Transcript

## Pointer A Pointer is a variable that holds the memory address of another variable. **Syntax for declaring a Pointer:** * `datatype * variable` * `int *IP;` **Memory map:** When a program is compiled, the ctt creates four logically distinct regions of memory. * Area to hold compiled code. *...

## Pointer A Pointer is a variable that holds the memory address of another variable. **Syntax for declaring a Pointer:** * `datatype * variable` * `int *IP;` **Memory map:** When a program is compiled, the ctt creates four logically distinct regions of memory. * Area to hold compiled code. * Area to hold global variables. * The Stack area to hold the returned address of functions called * The Heap area to allocate memory dynamically. **memory allocation:** The process of allocating memory space to store data elements is known as memory allocation. A memory can be allocated in two ways. * **Static memory allocation (Compile time memory allocation)**: When the amount of memory to be allocated is known before hand, and the memory is allocated during compile time, it's known as static memory allocation. For example: `int A;` * **Dynamic memory allocation (Run time memory allocation):** When the amount of memory to be allocated is not known before hand, rather it's required when required during run time, it's called dynamic memory allocation. **There are two types of operators associated with the dynamic memory allocation:** * **new:** The new operator is used to allocate the memory space dynamically. * **delete operator:** The delete operator is used to release the memory space allocated by a new operator. **An example of new and delete operator:** ```c++ #include<iostream.h> #include<conio.h> void main() { int *IP = new int; cout << "Enter an integer"; ``` **This Pointer:** The this pointer is an object pointer that points to the currently calling object. It is by default already available to each called member function. **Example of This Pointer** ```c++ #include <iostream.h> #include <conio.h> #include <string.h> class ABC { char Name [10]; public: ABC (char N[]) { strcpy(Name, N); } void Display() { cout << this->Name <<"\n"; } }; void main() { ABC A("RAM"), B("SITA"); A.Display(); B.Display(); getch(); } ``` **Array and Pointer** ```c++ #include <iostream.h> #include <conio.h> void main() { int: A [10], I; for (I=0; I<10; ++I) { Cout <<"Enter an integer"; } } ``` **Reduce the following function F (W,X,Y,Z) = Σ(0,4,6,7,8,12, 14, 15) using K. map:** |WX| 00 | 01 | 11 | 10 | |:---|:---|:---|:---|:---| | 00 | 1 | 0 | 0 | 0 | | 01 | 1 | 1 | 0 | 1 | | 11 | 1 | 0 | 1 | 1 | | 10 | 0 | 1 | 1 | 1 | **Quad 1:** $M_0+M_4+M_6+M_8$ $= \overline WX\overline Y\overline Z + \overline WX\overline YZ + \overline WXY\overline Z + \overline WXY Z + WX\overline Y \overline Z$ $= \overline Y \overline Z $ {Ref. W and X change their status to 80, these are removed} **Quad 2:** $M_7 + M_{12} + M_{14} + M_{15}$ $= \overline WX\overline YZ + \overline WX\overline YZ+ WXY\overline Z + WXYZ$ $= \overline X\overline Y $ {Ref. W and Z change their status to 80, these are removed} **Reduce the following function F(A,B,C,D) = Σ (5,6,7,10, 14, 15) using K map.** |AB| 00(CD) | 01(CD) | 11(CD) | 10(CD) | |:---|:---|:---|:---|:---| | 00 | 0 | 0 | 0 | 0 | | 01 | 0 | 1 | 1 | 1 | | 11 | 0 | 1| 1| 0 | | 10 | 0 | 0 | 1 | 0 | **Quad 1:** $ M_7 + M_{10} + M_{14} + M_{15}$ $= ABCD + ABCD + ABCD + ABCD$ $= ABCD$ **Find minimum POS expression of F(A,B,C,D)= Σ (0,1,3,5,7)** |CD| A+B| A+C| A+D| |---|---|---|---| | 0+0| 0+1| 0+1| 0+1| | C+0| 0+1| 1+1| 1+1| | 0+1|1+1| 1+1| 1+1| | C+D| A+B| 1+1| 1+1| $1^{st}$ Quad= $M_0.M_3.M_5.M_7$ = $(A+B)+(C+D).(A+B)+(C+D).(A+B)+(C+D)$. = $(A+B) + (C+D).$ **Find minimum SOP expression of F(A,B,CD) = Σ (0,18,23,10,5,7) / or solve K map where F (A,B,C,D) = Σ (0,8,2,310,5,7)** |AB| 00(CD) | 01(CD) | 11(CD) | 10(CD) | |:---|:---|:---|:---|:---| | 00 | 1 | 0 | 0 | 1 | | 01 | 1 | 1 | 1| 1 | | 11 | 1 | 1| 1| 0 | | 10 | 1 | 0 | 1 | 0 | $1^{st}$ Quad: $(AB)(CD) + (B)(CD) + (AD)(CD)+(AB)(CD)$ = $(AB)(CD)+(B)(CD)+(AD)(CD) + (AB)(CD)$ = $(BD)(C+D) + (A)(CD)$ = $(BD)(D+C) + (A)(CD)$ = $(BD)+(A)(CD)$ $2^{nd}$ Quad= $M_0 + M_1 + M_3 +M_6$ = $(AB)(CD) + (AB)(CD) + (AB)(CD) + (AB)(CD)$ = $(AB)(CD) + (AB)(CD) + (AB)(CD) + (AB)(CD)$ = $(AB)(C+D) + (AB)(C+D)$ = $(AB)+(C+D)$ **Reduce the following function F(A,B,C,D) = Σ (0,1,5, 6, 7, 10, 14, 15) using K map.** |AB| 00(CD) | 01(CD) | 11(CD) | 10(CD) | |:---|:---|:---|:---|:---| | 00 | 1 | 0 | 0 | 0 | | 01 | 1 | 1 | 1 | 1 | | 11 | 1 | 1 | 1 | 0 | | 10 | 1 | 1 | 1 | 0 | **Quad 1:** $M_1.M_5.M_7.M_{14}$ = $(A+B+C+D).(A+B+C+D).(A+B+C+D).(A+B+C+D)$ = $(A+B+D).(A+B+D)$ = $(A+D)$ **Quad 2:** $M_7.M_{10}.M_{14}.M_{15}$ = $(A+B+C+D).(A+B+C+D).(A+B+C+D).(A+B+C+D)$ = $(A+B+C).(A+B+C)$ = $(B+C)$ **Pair 1:** $M_0.M_1$ = $(A+B)(C+D).(A+B)(C+D)$ = $(A+B)(C+D) + (AB)(C+D)$ = $(A+B) + (AB)$ = $(AB)$ **Reduce the following function F(A,B,C) = Σ (0,1,3,4) using K map.** |BC| 00(A+B) | 01(A+B) | 11(A+B) | 10(A+B) | |:---|:---|:---|:---|:---| | 00| 1 | 0 | 0 | 1 | | 01| 0 | 1 | 1 | 0 | | 11| 0 | 0 | 1 | 0 | | 10| 1 | 1 | 1 | 1 | **Pair 1:** $M_0.M_4$ = $(A+B+C).(A+B+C)$ = $(B+C)$ **Pair 2:** $M_1.M_3$ = $(A+B+C).(A+B+C)$ = $(A+C)$ **Pair 3:** $M_0.M_1$ = $(A+B+C).(A+B+C)$ = $(A+B)$ **SOP = (B+C).(A+C).(A+B)** ## Universal Gates **NOR Gate:** The NOR gate has two or more input signals with one output signal. If all the inputs are zero, then the output signal is one, otherwise it is 0. | A | B | A+B | A+B | |---|---|---|---| | 0 | 0 | 1 | 0 | | 0 | 1 | 1 | 0 | | 1 | 0 | 1 | 0 | | 1 | 1 | 1 | 0 | **NAND Gate:** The NAND gate has two or more input signals with one output signal. If all the inputs are 1, then the output is 0; otherwise it is 1. | A | B | A.B | A.B | |---|---|---|---| | 0 | 0 | 1 | 1 | | 0 | 1 | 1 | 1 | | 1 | 0 | 1 | 1 | | 1 | 1 | 0 | 0 | **XOR Gate:** The XOR gate produces output 1 only for those input combinations that have an odd number of 1's. | A | B | A+B | | |---|---|---|---| | 0 | 0 | 0 | | | 0 | 1 | 1 | | | 1 | 0 | 1 | | | 1 | 1 | 0 | | **XNOR Gate:** The XNOR gate produces output 1 only for those input combinations that have an even number of 1's. | A | B | F | |---|---|---| | 0 | 0 | 1 | | 0 | 1 | 0 | | 1 | 0 | 0 | | 1 | 1 | 1 |

Use Quizgecko on...
Browser
Browser