"%"

what does the "%" do?

1
2
//eg. 
example % 4;


or....

print("%s example);

I have seen some codes that uses that sign in a "print" function, what does it do???
The number operator stands for MOD(Modulus)

It returns the remainder of example divided by 4.

If example was 9, it would return 1, if 8 or 4, would return 0.

Don't know about the print thing...
printf() is a C function used for printing to standard output (a.k.a. your command prompt, for instance). It takes a string including format specifiers, the %somethings you see. A simple example is:

1
2
int myVar = 15;
printf("myVar = %d", myVar);


The code reads the string and finds %d, which is a signal that it should print an integer value. It finds myVar, sticks that value into the string, and prints the string There are other format specifiers, like %c for a character, %s for a string, %f for a floating-point number, etc. etc.

It is also the modulus division operator, as Mayflower said.

If you are using C++, you shouldn't have to worry at all about format specifiers - cout and cin are pretty smart at figuring our what you are outputting/inputting.
The % character alone is the Modulus entity, which returns the remainder of the division between two given numbers. For instance (and I may have mixed these names up)...

1
2
3
int dividend=5, divisor=10, quotient, mod;
quotient=dividend / divisor;
mod=dividend % divisor;


Like Ganon11 said, the % character in combination with a single letter is probably a format specifier, as long as it's one of the existing letter combinations.
Topic archived. No new replies allowed.