
N00b Question
Sometimes people use &''s in there code, which seem to do something, but I don''t know what. Is this some kind of varible? I always thought & was AND and it also is Address Of. What does it do within a string array? Am I just crazy!
===========
Jack!!!!!!

===========Jack!!!!!!
The & operator has different functions/meaning. It depends on the context that it''s used in.
int i;
&i = in this case it represents a pointer to i
if(i&1) = in this case it represents a bitwise-AND
if((i==1)&&(j==1)) = in this case it represents a logical-AND
In a string array it is the same as case 1, it represents a pointer to the array.
...and, no, you''re not crazy. The compiler is smart enough to know what you want it to do based on the context that it''s used in.
int i;
&i = in this case it represents a pointer to i
if(i&1) = in this case it represents a bitwise-AND
if((i==1)&&(j==1)) = in this case it represents a logical-AND
In a string array it is the same as case 1, it represents a pointer to the array.
...and, no, you''re not crazy. The compiler is smart enough to know what you want it to do based on the context that it''s used in.
MSVC++ 6DirectX 7
If you mean something like
void foo(const string& str);
then & causes the str parameter be passed by reference, as opposed to by value.
void foo(const string& str);
then & causes the str parameter be passed by reference, as opposed to by value.
---visit #directxdev on afternet <- not just for directx, despite the name
Yes, I relise these but I have seen it in a diffrent meening. I will try and get an example for you (If I can''t, i guess I am just crazy and seeing things
).
Thank-you.
===========
Jack!!!!!!

Thank-you.
===========
Jack!!!!!!
===========Jack!!!!!!
Example:
printf("%hello all",something);
Does the %NAME get changed, Perl style?
===========
Jack!!!!!!
[edited by - Jack Of Null Pointer on May 3, 2002 5:30:31 PM]
printf("%hello all",something);
Does the %NAME get changed, Perl style?
===========
Jack!!!!!!
[edited by - Jack Of Null Pointer on May 3, 2002 5:30:31 PM]
===========Jack!!!!!!
That''s C stuff. It''s used to display text in console applications.
For instance:
int var = 2351;
printf("%i people suffer from voice immodulation.", var);
... would display "2351 people suffer from voice immodulation."
The ''%i'' represents something that should be replaced as an integer value (conveniently provided by the variable ''var'').
You can add multiple arguments, like so:
printf("%i bottles of %s on the wall, %i bottles of %s (contd)", 100, "beer", 100, "beer");
The integer 100 and the string beer can be variables or actual numbers and strings, respectively. The %i is replaced by 100, and the %s is replaced by beer. If you were to switch the order of the 100 and the beer around at the end of the printf statement, you''d get problems because "beer" would be read as an integer and 100 as a character string.
%c is the character format specifier
%i is the integer format specifier
%f is for floats
%s is for strings
... and so on and so forth.
Hope that helps!
For instance:
int var = 2351;
printf("%i people suffer from voice immodulation.", var);
... would display "2351 people suffer from voice immodulation."
The ''%i'' represents something that should be replaced as an integer value (conveniently provided by the variable ''var'').
You can add multiple arguments, like so:
printf("%i bottles of %s on the wall, %i bottles of %s (contd)", 100, "beer", 100, "beer");
The integer 100 and the string beer can be variables or actual numbers and strings, respectively. The %i is replaced by 100, and the %s is replaced by beer. If you were to switch the order of the 100 and the beer around at the end of the printf statement, you''d get problems because "beer" would be read as an integer and 100 as a character string.
%c is the character format specifier
%i is the integer format specifier
%f is for floats
%s is for strings
... and so on and so forth.
Hope that helps!
-----------------"Who the hell wants to hear actors talk?" - H. M. Warner"Everything that can be invented has been invented." - Charles H. Duell"I think there is a world market for maybe five computers." - Thomas Watson, Chairman of IBM (1943)
I believe that %i and %d are equivalent. Both mean signed integer. On the other hand, formatting codes like these are C-style (as well as printf). If you use C++ and iostreams (cout <<), then you don''t need them.
/Ksero
/Ksero
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement