Oct 26 2022 Flashcards

1
Q

Syntax of getting address of variable using pointers

A

&p

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is declaration of Pointer

A

*p

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is initialization of Pointer

A

p = &alpha

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

int *p;
p = &x
cout&laquo_space;*p ;

what gets printed

A

The value of x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

int p;
p = &x
cout«“
p”;

what gets printed

A

The value of x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what does & do

A

Gets the address of the variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what does * do in pointers

A

Declaration or Dereferencing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How is memory divided while your function is running

A

Stack , Heap , Stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What section can main function access in the memory

A

Main Function and Stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is point of pointers

A

The main function needs pointer to access heap or file on a disk/printer/network connection/keyboard/mouse/monitor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Heap Memory is accessed dynamically

A

Size of Memory required in the heap is decided at runtime and not compile time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between heap array and stack array while creation

A

The new keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

When you use the new keyword you must you include and what is the syntax

A

pointer

1 -> int *p ;
p = new int[5]

2-> int *p = new int[5]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How it the effect of memory when it goes out of scope

A

Stack memory is deleted but heap memory is not deleted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to delete an array in Heap

A

delete []p
p = null

The sequence is imp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is memory leak

A

memory in the heap that you can not access any more

16
Q

how can you access the arr in the heap

A

exactly the same way as you can access the arr in stack

16
Q

What address does the pointer have when it is pointing to the array how can you access the arr in the heap

A

the zero index

17
Q

what does p++ mean and how much does the pointer move by

A

p++ means move to the next index address and move by the number of bytes that is occupied by one element

18
Q

What 5 arithematic operations can pointers perform and why cant you do other operations

A

p++
p–
p= p + constant
p = p - constant
d = q - p / 2 where q and p are pointers
beacuse they dont make sense

19
Q

What can be potential errors using pointers

A

Uninitialized Pointer
Memory Leak
Dangling Pointer

20
Q

Explain Dangling Modifier Problem that can be caused by pointers

A

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

21
Q

Why is Java called a managed Language

A

They dont have pointers and JVM deals with the problems that might be caused by pointers