Archived

This topic is now archived and is closed to further replies.

Jack of Null Pointer

N00b Question

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites