c++ - initialize char array with quotes and curly braces -
i'm little confused. logically difference between these codes?
#include <iostream> using namespace std; int main(){ char a[5]="abcd"; // cout << a; return 0; }
second is
char a[5]={"abcd"}; //
third is
char a[5]={'a','b','c','d'}; //
char a[5]={"abcd"}; char a[5]={'a','b','c','d','\0'};
in both cases, array of characters a declared size of 5 elements of type char: 4 characters compose word "abcd", plus final null character ('\0'), specifies end of sequence , that, in second case, when using double quotes (") appended automatically.attention adding null character separating via commas. series of characters enclosed in double quotes ("") called string constant. c compiler can automatically add null character '\0'
@ end of string constant indicate end of string.
source:this link can better
Comments
Post a Comment