String Literals

前端 未结 3 866
走了就别回头了
走了就别回头了 2020-11-27 19:30

I have few doubts about string literals in c++.

char *strPtr =\"Hello\" ;
char strArray[] =\"Hello\";

Now strPtr and strArray are considere

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 20:02

    The older C and C++ compilers were purely based on low level coding where higher standards of data protection were not available, and they can not even be enforced, typically in C and C++ you can write anything you want..

    You can even write a code to access and modify your const pointers as well, if you know how to play with the addresses.

    Although C++ does enforce some compile level protection, but there is no protection on runtime. You can certainly access your own stack, and use its values to manipulate any data that came in const pointer as well.

    That is the reason C# was invented where little higher level standards are enforced because whatever you access is reference, it is a fixed structure governing all rules of data protection and it has hidden pointer which can not be accessed and nor modified.

    The major difference is, C++ can only give you compile time protection, but C# will give you protection even at runtime.

提交回复
热议问题