question about the FizzBuzz test

Hi, I am a new programmer and I found out about a somewhat funny test they give people for jobs that a lot of programmers end up failing. You have all probably heard of it but here is the complete code for it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;


int main()	
{
for( int i=1; i<=100; i++)
{
if(i%3==0)
printf("Fizz");
if(i%5==0)
printf("Buzz");
if(i%3!=0 && i%5!=0)
printf("%d",i);
printf("\n");
}
return 0;
}



Now I understand everything as it is pretty damn simple but I don't understand what the "%d" means. The full line is printf("%d",i); If I run it without the d it messes up everything. I know what the , does but not %d? Please explain
(I hope they aren't giving printf tests for C++ interviews).

The %d just means you are going to be printing out an integer in that place(which happens to be whatever the value of i is).

You can see what all of the different letters/symbols mean here.
http://www.cplusplus.com/reference/cstdio/printf/
Yea ok, I just wrote the program with cout<< instead... why do people even use printf???
The main reason being printf is C, cout didn't exist. You should be fine using cout for C++.
Topic archived. No new replies allowed.