C Programming Pointer management a Show the output of the fo

C++ Programming:

Pointer management

a) Show the output of the following code segment:

int a(1);

int b(2);

int *p1, *p2;

p1 = &a;

p2 = &b;

*p1 = *p2;

*p2 = 10;

cout << *p1 << \' \' << b << \' \' << a << endl;

b) Describe the problem with this function:

void foo()

{

int *array = new int[100];

for(int i = 0; i < 100; i++)

{

//do something

}

}

Solution

a) given program:

int a(1);

int b(2);

int *p1, *p2;

p1 = &a;

p2 = &b;

*p1 = *p2;

*p2 = 10;

cout << *p1 << \' \' << b << \' \' << a << endl;

Answer) Output for the above code segment is

Output: 2 10 2

b)

void foo()

{

int *array = new int[100];

for(int i = 0; i < 100; i++)

{

//do something

}

}

The above program shows an error message if want to return a value from function foo() to the main() function then it shows function returning \'void\'

It shows that the function is not declared here because no match for operator.here we are declaring main() function as integer type and foo() funtion of type void

if we want to execute the above code segment then function foo() must be of type integer.

C++ Programming: Pointer management a) Show the output of the following code segment: int a(1); int b(2); int *p1, *p2; p1 = &a; p2 = &b; *p1 = *p2; *p2
C++ Programming: Pointer management a) Show the output of the following code segment: int a(1); int b(2); int *p1, *p2; p1 = &a; p2 = &b; *p1 = *p2; *p2

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site