简体   繁体   中英

Printing C array on Console

#include <stdio.h>

int main(void) {
    // your code goes here

    char d[] = {1, 2, 3, 4, 5,6};

    printf("%s" ,d);
    int i ;
    for(i = 0; i < 6 ; i++)
        printf("%c " , d[i]);

    printf("\n");

    return 0;
}

I tried this small snippet on ideone.com. I was not able to get any output on console. Can someone please let me know whats wrong here?

Replace this:

    printf("%c " , d[i]);

with

    printf("%d " , (int)d[i]);

Assuming you want to treat the items in d as numbers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM