News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

c++ array tips - Initializing character arrays

Started by ben2ong2, October 06, 2006, 05:59:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ben2ong2

[ This information adapted from the C FAQ from comp.lang.c. ]


5.16:   Is char a[3] = "abc"; legal?  What does it mean?

A:   Yes, it is legal; it declares an array of size three,
   initialized with the three characters 'a', 'b', and 'c', without
   the usual terminating '\0' character.

   References: ANSI Sec. 3.5.7 pp. 72-3.


[ A preferable form for the above would be as below; it could avoid
  introducing a bug in dealing with non-null-terminated strings. -adc

  char a[] = "abc"; ]


You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login