dimanche 29 septembre 2019

Why char array is not printing value?

I am simply trying to print char array after copying some data into it. But cout does not print anything. What is wrong with below code?

Thank you for your help.

int main() {
    char addr[6];
    int id = 2;
    short port = 1;
    memcpy(&addr[0], &id, sizeof(int));
    memcpy(&addr[4], &port, sizeof(short));

    cout << "addres:" << addr << endl;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire