Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to use printf to print an array in C language
How to use printf to print an array in C language

#include??//Add header file printf() for use

int?main()

{ ?

int?a[5]={1,2,3,8,9};?

//printf("%d",a[5]);?//a [5] Indicates that the sixth element of array a is out of bounds?

//The integer array cannot be simply output at once, and a loop must be used

int?i;< /p>

for(?i=0;i<5;i++?)

printf("%d?"?,?a[i]?);

printf("\n");

getch();

return?0;

}

Extended information

contains the data to be output, which can be constants (character constants, numeric constants, string constants), variables, and calculation expressions. The data here should correspond one-to-one with the format control characters in the previous format (an error will occur if they do not correspond).

For example:

int?a=1;float?b=1.0;

char?str[12]="Hello?World";printf("This?is?an? example?of?printf:\n");

printf("a?is?%d,b?is?%f,and?a+b=%f",a,b,a +b);printf("I?want?to?say,%s",str);

Reference: Baidu Encyclopedia - printf