Hi find the error Its C not C Find the error in each of the
Hi
find the error. It\'s C not C++
Find the error in each of the following program segments. If the error can be corrected, explain how.Solution
1. It will not give any error but it will print a garbage value. You can correct it by initializing it to 0 like- *number=0 after first line.
2. You can not assign a float pointer value to long pointer value.
3. Since x is a pointer so the value that should be assigned is address of y. Correction- x=&y;
4. Since s is a char array we can\'t increment it like this as it is treated as constant . Correction-
char *temp=s;
for(;*temp!=\'\\0\';temp++)
printf(\"%c \",*temp);
5. Generic pointer value needs to be cast before use. Correction-
result=(short)*genericPtr +7;
6. Pointer are the variables that stores address so second line is wrong. Correction- xPtr=x;
7. This will also print some garbage value.
