C Programming: The Array And Printf

Eye catch: C programming C Programming

Lets’s learn the Array And how to Printf.

Let’s check the video above and the source code under next output screenshot.
image: Output; C sutudy code Array and Printf

#include

int main(void)
{

int numbers[] = {65,75,85};

int i;

printf(“Lets’s check the array and how to printf it!\n”);
printf(“\nFirstly, try int attay next;\n”);
printf(“int numbers[] = {65,75,85}\n\n”);

printf(“Let’s output values in this int array.\n”);

printf(“\n%%d is valid, taking out values, one by one.\n”);
for (i = 0; i < 3; ++i)
printf(“[%d]: %d “, i, numbers[i]);
printf(“\n”);

printf(“\n%%c is could be used as well.\n”);
printf(“But they are displayed as corresponding charcters of ASCII table.\n”);
for (i = 0; i < 3; ++i)
printf(“[%d]: %c “, i, numbers[i]);
printf(“\n”);

printf(“\nThen, %%s.\n”);
printf(“The statement below is invalid.\n”);

printf(“\nprintf(\”%%s\”, numbers);\n”);
printf(“Because, it’s for the char array, which is terminated by ‘\\0′.\n\n”);

printf(“So now, Let’s try next char array.\n”);

char chr_arr[] = {65,75,85,’ ‘,’A’,’K’,’U’};

printf(“char chr_arr[] = {65,75,85,’ ‘,’A’,’K’,’U’}\n\n”);

printf(“%%s,\n%s \n\n”, chr_arr);

printf(“%%c, taking out one by one\n”);
for (i = 0; i < 7; ++i)
printf(“[%d]: %c “, i, chr_arr[i]);
printf(“\n\n”);

printf(“%%d, taking out one by one\n”);
for (i = 0; i < 7; ++i)
printf(“[%d]: %d “, i, chr_arr[i]);

printf(“\n\n”);

return 0;
}

タイトルとURLをコピーしました