I was trying to use an "out int" parameter in one of my functions. How should I declare the variable that I am passing to it?

You should declare the variable as an int, but when you pass it in you must specify it as 'out', like the following:

int i;

foo(out i);

where foo is declared as follows:

[return-type] foo(out int o) { }

Showing Answers 1 - 7 of 7 Answers

ans:

Definition:

Out

A parameter declared with an out modifier is an output parameter.

A variable must be definitely assigned before it can be passed as a reference parameter in a function member invocation. A variable must be definitely assigned  before it can be passed as a reference parameter in a function member invocation.

example

int x=4

calling function

Functioname(out int x)

  Was this answer useful?  Yes

blue

  • Jun 13th, 2007
 

You are wrong "sahu".
You pass out parameters when you don't want to initialize the variable before entering a function. But the variable must be initialized within the function.

  Was this answer useful?  Yes

bhavkins

  • Aug 15th, 2007
 

It is true that you use out when you don't want to initialise the variable and force the called function to initialise and assign proper value.

But this mechanism doesn't stop you from initialising the variable you are passing with out parameter.
The only thing the compiler forces is to initialise the variable inside the function.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions