hi
can any one give me an example of pointer??
hi
can any one give me an example of pointer??
int* ptr;
#include <iostream.h>
void main()
{
int var = 50;
//next 2 lines create and initilize
int *pvar;
pvar = &var;
cout << "The variable var, pointed to by pvar, is: ";
cout << *pvar << ".\nvar is located at adress: ";
cout << pvar << endl;
}
the benifit of this is you can manipulate variables that are out of scope (if you want to change a variable outside your function or whatever you can pass the adress)
=@-OmegatronO-@=
>the benifit of this is you can manipulate variables that are out of scope
The disadvantage is that your whole program is undefined. Don't use void main.
-Prelude
My best code is written with the delete key.
thanks
thanke you v mat.
sry bout that
twas just an example
=@-OmegatronO-@=
what is so bad about voiding main()? In my c++ class, we were told to not even delcare main(), as such:
Code:#include <iostream.h> main() { cout << "Hello"; return 0; }
It obviously does the same as int main(), but still, why at all?
Environment: OS X, GCC / G++
Codes: Java, C#, C/C++
AOL IM: neandrake, Email: neandrake (at) gmail (dot) com
>what is so bad about voiding main()?
It's wrong, the standard specifies that main is to return an int, if it doesn't you never know what will happen. The chances of something horrible happening really are slim, but that doesn't make an undefined construct any safer.
>In my c++ class, we were told to not even delcare main()
That's acceptable since an empty return value is implied to be int. Personally, I prefer to stay as standard as I can and the standard says either
int main ( void )
or
int main ( int argc, char **argv )
When I was learning C, my instructor recommended the use of void main. At the time I thought he was amazing but now I realize that his knowledge of both the language in general and the standardized language was very basic. The point is, don't always believe the first thing you're told, research it and find out for sure if it's correct, you never know when the person teaching you is only one step ahead of you in learning. Though since I've shunned void main I've forever alienated myself from that job at Microsoft.
-Prelude
My best code is written with the delete key.
howdy,
the way i understand it is that the OS CAN react negatively to a return value other than 0 when execution end thus:
int main()
{....
.....
.....
return 0;
}
signals the OS that execution ended cleanly.
M.R.
what do you mean?(if you want to change a variable outside your function or whatever you can
pass the adress)