Oct 26 2022 Flashcards
(23 cards)
Syntax of getting address of variable using pointers
&p
What is declaration of Pointer
*p
What is initialization of Pointer
p = &alpha
int *p;
p = &x
cout«_space;*p ;
what gets printed
The value of x
int p;
p = &x
cout«“p”;
what gets printed
The value of x
what does & do
Gets the address of the variable
what does * do in pointers
Declaration or Dereferencing
How is memory divided while your function is running
Stack , Heap , Stack
What section can main function access in the memory
Main Function and Stack
What is point of pointers
The main function needs pointer to access heap or file on a disk/printer/network connection/keyboard/mouse/monitor
Heap Memory is accessed dynamically
Size of Memory required in the heap is decided at runtime and not compile time
What is the difference between heap array and stack array while creation
The new keyword
When you use the new keyword you must you include and what is the syntax
pointer
1 -> int *p ;
p = new int[5]
2-> int *p = new int[5]
How it the effect of memory when it goes out of scope
Stack memory is deleted but heap memory is not deleted
How to delete an array in Heap
delete []p
p = null
The sequence is imp
What is memory leak
memory in the heap that you can not access any more
how can you access the arr in the heap
exactly the same way as you can access the arr in stack
What address does the pointer have when it is pointing to the array how can you access the arr in the heap
the zero index
what does p++ mean and how much does the pointer move by
p++ means move to the next index address and move by the number of bytes that is occupied by one element
What 5 arithematic operations can pointers perform and why cant you do other operations
p++
p–
p= p + constant
p = p - constant
d = q - p / 2 where q and p are pointers
beacuse they dont make sense
What can be potential errors using pointers
Uninitialized Pointer
Memory Leak
Dangling Pointer
Explain Dangling Modifier Problem that can be caused by pointers
Pointer was initialized (p), then another was initialized ( x) to same address ,arr was deleted using x and now you are trying to access y
Why is Java called a managed Language
They dont have pointers and JVM deals with the problems that might be caused by pointers