What is wrong with the following code snippets Work in pairs

What is wrong with the following code snippets? Work in pairs and turn in a piece of paper. int a; int* ptr; ptr = a; int a; char* ptr; ptr = &a; float f = 5.0; float* ptr_1 = &f; float* ptr_2 = *ptr_1; int a; int* ptr_1 = &a; char* ptr_2; ptr_2 = ptr_1; int a; int* ptr_1 = &a; int* ptr_2; ptr_1 = ptr_2;

Solution

//first line

a) add &(address operator) before the last a

ex:

//corrected code

int a;

int *ptr;

ptr=&a;

//second line

2)here normal variable is int.so pointer variable should also be declared as int instead of character.(char)

//corrected code

int a;

in *ptr;

ptr=&a;

//third line

//In third line use float *ptr_2=& ptr_1 instead of float *ptr_2=* ptr_1

//corrected code

float f=5.0;

float *ptr_1=&f;

float *ptr_2=&ptr_1;

//fourth line and fifth line is proper

 What is wrong with the following code snippets? Work in pairs and turn in a piece of paper. int a; int* ptr; ptr = a; int a; char* ptr; ptr = &a; float f =

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site