Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Null as an array element in C/C++

Tags:

arrays

c

I want to have \0 as one of my array (char type) element in my C/C++ code but not the last one. I am doing this.

char arr[10]  ; //array declaration
//initializing the array
arr[0] = 'a'  ;
arr[1] = '\0' ;
arr[2] = 's'  ;

When i try printing these array elements, i get some symbolic stuff as output for a[1]. I guess 0 is converted to char. Is that so ? If yes, can't i have \0 anyhow in my array before the termination ?

like image 967
CodeBlaster Avatar asked May 01 '26 11:05

CodeBlaster


1 Answers

'/0' is not a null character. Escaping uses a backslash: '\0'.

like image 165
danfuzz Avatar answered May 03 '26 00:05

danfuzz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!