Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/* • The following code consists of 5 parts. • Find the errors for each part and

ID: 3849930 • Letter: #

Question

/*

•   The following code consists of 5 parts.
•   Find the errors for each part and fix them.
•   Explain the errors using comments on top of each part.


*/


#include <stdio.h>
#include <string.h>

int main( ) {


//////////////////////////////////////////////////////////////////////////
//////////////        Part A. (5 points)                //////////////////

int *number;
printf( "%d ", *number );

//////////////////////////////////////////////////////////////////////////
//////////////        Part B. (5 points)                //////////////////


float *realPtr;
long *integerPtr;
integerPtr = realPtr;


//////////////////////////////////////////////////////////////////////////
//////////////        Part C. (5 points)                //////////////////


int * x, y;
x = y;

//////////////////////////////////////////////////////////////////////////
//////////////        Part D. (5 points)                //////////////////


char s[] = "this is a character array";
int count;
for ( ; *s != ''; ++s)
    printf( "%c ", *s );


//////////////////////////////////////////////////////////////////////////
//////////////        Part E. (5 points)                //////////////////


float x = 19.34;
float xPtr = &x;
printf( "%f ", xPtr );


return 0;
}

Explanation / Answer

A)

Program :

int *number;
printf( "%d ", *number );

Correct Program :

#include<stdio.h>
int main(void)
{
int *number;
int temp=1;
number=&temp;
printf( "%d ", *number );
}

Output :

1

B)

float *realPtr;
long *integerPtr; // long to float conversion not possible
integerPtr = realPtr;

Correct Number :

#include<stdio.h>
int main(void)
{
float *realPtr;
float *integerPtr;
integerPtr = realPtr;
}

C)

int * x, y;
x = y; // The assign value to the pointer is always address, so we need to change.

Correct Program :

#include<stdio.h>
int main(void)
{
int * x, y;
x = &y;
return 0;
}

D)

char s[] = "this is a character array";
int count;   
for ( ; *s != ''; ++s) // create a new pounter to do this operation
    printf( "%c ", *s );

Correct program :

Output :

E)

Correction :
printf( "%f ", xPtr );

change it as printf( "%f ", *xPtr );

Correct program :

#include <stdio.h>
int main(void)
{
float x = 19.34;
float *xPtr = &x;
printf( "%f ", *xPtr );
return 0;
}

Output :

19.340000