In this code what is the role of the symbol %3d
? I know that % means refer to a variable.
This is the code:
#include <stdio.h>
int main(void)
{
int t, i, num[3][4];
for(t=0; t<3; ++t)
for(i=0; i<4; ++i)
num[t][i] = (t*4)+i+1;
/* now print them out */
for(t=0; t<3; ++t) {
for(i=0; i<4; ++i)
printf("%3d ", num[t][i]);
printf("\n");
}
return 0;
}
As % has special meaning in printf type functions, to print the literal %, you type %% to prevent it from being interpreted as starting a conversion fmt.
Re “What does printf ("%5D") mean in C?”, it means nothing. It's a syntax error and won't even compile.
%3d can be broken down as follows: % means "Print a variable here" 3 means "use at least 3 spaces to display, padding as needed" d means "The variable will be an integer"
%3d
can be broken down as follows:
%
means "Print a variable here"3
means "use at least 3 spaces to display, padding as needed"d
means "The variable will be an integer"Putting these together, it means "Print an integer, taking minimum 3 spaces"
See http://www.cplusplus.com/reference/clibrary/cstdio/printf/ for more information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With