c# - What is the output, if we use a "character pointer" as an index to a character array in C++ and how to achieve this in c SHarp? -
i have vc++ character array "wchar_t arr[0x30] = { 0x0,0x1,..., 0xc...hexadecimal initialization here ......}". there 1 more c++ character pointer wchar_t * xyz.
operation like---- wchar_t ch = arr[xyz[2]] done. can kindly explain in detail happening in this, because arr[] char array , should pass integer index array right? here index passed character array "arr[] " character pointer xyz[2]. in above code suppose character 'a' stored @ xyz[2] mean indexing c++ character array this--- arr[xyz[2]] becomes arr['a']. kindly let me know. how can achieve in c sharp.. if know happening in c++ code above can myself achieve in c sharp. can kindly let me know happening here in c++ code.
what happens wchar_t
stored @ xyz[2]
promoted int
, used index arr
array.
it means that, if xyz[2]
contains l'a'
, program exhibit undefined behavior, since arr
has space 48
items l'a'
promoted 97
.
concerning second part of question, c# only supports pointer arithmetic inside unsafe
blocks, you'll want use arrays instead:
char[] arr = new char[0x30]; char[] xyz = something(); char ch = arr[xyz[2]];
Comments
Post a Comment