I was wondering how to access individual elements in the below case:
char *three=(char*){'2','5','8','\0'};
If the assignment were like this:
char *three="258";
it can be accessed with three[0],three[1].....etc. How to access in the first case? Thanks in advance...
First of all char *three=(char*){'2','5','8','\0'}; is not valid C. To make a compound literal you must do like this:
char *three=(char[]){'2','5','8','\0'};
When that is fixed, then there is no difference in how you access the data. In both cases you can use the [] operator to access data, it can be used on any pointer type. Where the pointer points at doesn't matter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With