2020-05-12

Why does printing the name of an array fail to return a pointer but a string ?



#include <iostream>
#include <vector>

int main(void) {
        char a[] = "HELLO";
        std::cout << a << std::endl;
        return 0;
}

See above code
I learn from the book that

In char a[] = "HELLO"; a is automatically degraded to the pointer of the first element of array,

Here it should be 'H'

So a is a pointer

But when printing a ,

I get HELLO

Why?

No comments:

How to Add a Directory to PATH in Linux

 https://linuxize.com/post/how-to-add-directory-to-path-in-linux/ When you type a command on the command line, you’re basically telling the ...