it puts '0' in every cellCode:char arr[256]={'0'};
??
it puts '0' in every cellCode:char arr[256]={'0'};
??
No. And I'm pretty sure we've talked about this before.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
i remember that we could put in every cell of an array one value
by a similar way
??
Listen to matsp. You can find dozens of pages explaining this in google.
PS: Really sure it's '0' and not 0?
Only to the value zero (not '0', that's the character representing the digit zero, commonly the value 48, but not guaranteed). For any constant other then zero, you will have to either enter all the 256 values [16 rows of 16, for example], or write code to fill in the values - e.g. use memset().
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
actually it was 0
but i though it was '0' because its a array of chars
not an array of integers
??
i cant put 0 into char array
its a number
??
Then you can't put '0' in a char array either, since it is also a number (of type int, in fact).Originally Posted by transgalactic2
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
the ascii value of 0 is NULL
so it puts NULL in every cell
and i can do this shortcut
only with NULL value
can i do
Code:char arr[256]={67};//the letter that 67 represenst
The null character has a value of 0, and this is true with ASCII as well. However, the macro NULL is different in meaning from the null character, even though they are equal and may have the exact same value and type. Consequently, it is usually semantically wrong to say that "it puts NULL in every cell" unless you are talking about an array of pointers.Originally Posted by transgalactic2
This "trick" works with zero values, including NULL, because those elements of the array that are not explicitly initialised will then be zero initialised.Originally Posted by transgalactic2
Yes, but you will end up with an array for which arr[0] has the value of 67 and the rest have the value of 0.Originally Posted by transgalactic2
EDIT:
No, '0' is an int, and the char type is an integer type.Originally Posted by transgalactic2
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
ya i just tested it works withbut fills only arra[0] not all array other will be NULLCode:char arr[256]={67}
so if want to initialize arr without a loopCode:char arr[256]={0};
i can put only NULL char in them
You could simply write out 67 256 times
Or you could use memset().
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Maybe even a for-loop, but memset is often more optimized. Or, if you don't mind a trailing NUL:
BTW: NULL is "(void *)0", NUL is "(char)0".Code:char arr[] = "00000000000000000000000000000000000000000000000"...;