View Single Post
  #3 (permalink)  
Old July 29th, 2003, 04:50 PM
7stud 7stud is offline
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi nigor,

Quote:
quote:I've read that it is important to initialize a variable upon definition, that way the variable will not be assigned memroy space that might contain junk values.
That is good practice.

Quote:
quote:So, for example, in a function like 'int text(int x, int y)', are x and y automatically initialized to zero...
No they are not. When you declare a function like:

int text(int x, int y)

you are not defining x and y, so you're first statement doesn't apply. In addition, I don't recommend Ankur_Verma's recommendation to provide default values--providing default values and intializing your variables are two different subjects.

x and y are the parameters of your function, and they don't need initializing. You should think of them as place holders for the data you are going to send the function. For instance your function might be defined like this:
Code:
int text(int x, int y)
{
   int result = 0;
   result = x + y;
   return result;
}
You would call that function like this:

int a = 10;
int b = 20;

text(a, b);

Then the value for a will be substituted for x, and the value of b will be substituted for y in the function.
Reply With Quote