Bo Master this time to write some C program code, because before the C is not a lot of understanding, it encountered a lot of bottlenecks, of course, there are many interesting methods can be used to solve these problems, the following problem is the blogger encountered a trouble.
Declare the int, long type, and other local variables, after using some methods to assign values to these variables, to determine whether these variables are really assigned initial value, how to do?
Of course, if you do not assign a value to a local variable, this can cause the entire program to crash, because its contents are directed by the system to the garbage memory.
Let's look at a piece of code here:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int globle_value;
int my_sum (int value1, int value2);
Long My_sub (long value1, long value2);
int main (void)
{
int auto_value_int;
Long Auto_value_long;
Auto_value_int = My_sum (9);
Auto_value_long = My_sub (12587, 22587);
printf ("Globle_value:%d\n", globle_value);
printf ("Auto_value_int:%d\n", auto_value_int);
printf ("Auto_value_long:%ld\n", Auto_value_long);
System ("PAUSE");
return 0;
}
int my_sum (int value1, int value2)
{return
value1 + value2;
}
Long My_sub (long value1, long value2)
{return
value2-value1;
}
Description
I first defined a global variable, which, of course, was automatically initialized by the system to 0, but two different types of local variables were not initialized, but were assigned values through two function calls. But now, to think of a problem, two function calls are not executed successfully? How can I judge if I do not succeed, or do not achieve the effect I want?
At first, bloggers did not think of a good solution, also consult others how to do, not too much harvest, however, the blogger thought of a C language function--sprintf, it can be different types of variables stored in the character array, we can then judge whether the character array is empty.