Define a pointer to store the address of a value x Define a

Define a pointer to store the address of a value \'x\'. Define a pointer to store the address of a vector of strings. Consider the statement: int* p = new int [20]; How do you deallocate the memory just allocated? What are the issues with the following function? void foobar() {int x=10; int* q=&x; int* p=new int[5]; delete q; delete &x;}

Solution

1) int variable = 10;

int *pointer = &variable; --> defining a pointer variable and storing address of varible

cout<<\"Value: \"<<variable;

cout<<\"Address: \"<<pointer;

2)   char s1[] = \"Hello\", s2[] = \"World\";

char *p1 = vec[0];

char *p2 = vec[1];

3) int *p = new int[20];

delete[] p; --> deallocation of pointer array memory

4) i) Three variable declared and two varibales deallocated.

ii) One warning, p is assigned a value and that is never used.

iii) And the value of x chages depends on the address locations of memory mapping

 Define a pointer to store the address of a value \'x\'. Define a pointer to store the address of a vector of strings. Consider the statement: int* p = new int

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site