Re: [Dev-C++] whats wrong with this?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Lloyd <ll...@cd...> - 2007-05-21 08:55:17
|
Sorry some typing error are occured... please check this mail...
On Mon, 2007-05-21 at 14:25 +0530, Lloyd wrote:
> Hi ,
>
> This is a small program and its output
>
> #include<iostream>
> using namespace std;
>
> bool call(int *a)
> {
> static int x;
> ++x;
> int *temp=new int;
> *temp=x;
> a=temp;
> cout<<"call->"<<x<<","<<*a<<endl;
> return true;
> }
>
> int main()
> {
> int *a;
> for(int i=0;i<10;++i)
> {
> call(a);
> cout<<"val->"<<*a<<endl;
> }
> return 0;
> }
>
> Output
> call->1,1
> val->0
> call->2,2
> val->0
> call->3,3
> val->0
> .......
> ....
>
> The output which I wanted is
>
> Output
> call->1,1
> val->1
> call->2,2
> val->2
> call->3,3
> val->3
> ......
> .....
>
> The modification of the pointer in the function is not reflected in the
> calling function. Would anybody tell me the reason for this mistake?
>
> Thanks and Regards,
> Lloyd
>
>
>
>
> ______________________________________
> Scanned and protected by Email scanner
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
______________________________________
Scanned and protected by Email scanner
|