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

find the error in the C program and explain how to correct it Find the error in

ID: 3775892 • Letter: F

Question

find the error in the C program and explain how to correct it

Find the error in each of the following program segments. If the error can be corrected, explain how. int *number; printf("%d ", *number); float *realPtr; long *integerPtr; integerPtr = realPtr; int * x, y; x = y; char s[] = "this is a character array"; int count; for (; *s != ''; ++s) printf("%c ", *s); short *numPtr, result; void *genericPtr = numPtr; result = *genericPtr + 7; float x= 19.34; float xPtr = &x; printf("%f ", xPtr); char *s; printf("%s", s);

Explanation / Answer

a)In this,we are creating pointer but we are not pointing to valid memory location.So,when we call print it will access invalid memory hence generate segmentation fault.

int* number;

int a=5;

number=&a;

b)It will show warning because we are trying to assign float pointer to long pointer.Make either one of pointer to same data type

c)Instead of x=y write x=&y because pointers take address of variable

d)It will generate i value error as we cant use array in terms of pointer to access elements.

char s[]="this is array";

int count=sterlen(s);

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

printf("%c",s[i]);

e)We cant do arithmatic operation on void pointer need to type cast it

f)We cant asssign address of float to float variable .It should be float pointer.

float x=19.3'

float *xptr=&x

h)

In this,we are creating pointer but we are not pointing to valid memory location.So,when we call print it will access invalid memory hence generate segmentation fault.