In this paper, we analyze the attention points of automatic implicit conversion and type casting in C language through a C program instance, as follows:
First look at a C program:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
double proc (int q) {
int n;
Double sum,t;//The key to this example is sum = 2.0 on the types of these variables
;
while (sum<=q) {
t=sum;
sum = sum+ (n+1)/n;//automatically implicitly converts
sum =sum + double ((n+1)/n);/type cast
n++;
return t;
}
void Main () {
system ("C");
printf ("%f\n", proc)
}
Analysis:
When we see sum = sum+ (n+1)/n; Such a statement always casts an unthinking force on the variable n, but there is another word in C. "When a low precision data type and a high-precision data type operation, the result of the operation is a high-precision type." "Don't be confused at this time, it just emphasizes the result." In order for others to understand what we want to do with the data, it is best to cast it. In this case, the so-called low precision to high-precision automatic implicit conversion is actually a forced type conversion.