Похожие чаты

Can someone explain why I got: "Segmentation fault" this time? I've

no idea how to search for a solution to this issue.

14 ответов

25 просмотров

Which language is this ?

You're initializing a char* using a const char* which is wrong by itself because it may cause the error you're going to get like that one.

In short, char* cannot be changed. It's a const.

Extending what Sahand said, in C char* ptr = <string-literal>; This gives you a pointer to a string literal which is not modifiable (it is in the text segment in asm generated which is read only). If you wish to modify the string use the literal to initialize an array char str[] = <string-literal>; Unlike the above case it'll create the array on stack using the literal. Which should allow you to modify the array

Emmanuel_230001007
Which language is this ?

It's C, which shouldn't be surprising considering we are in a C/C++ group.

Ali-Ayed / FREE PALESTINE 🇵🇸 Автор вопроса
Emmanuel_230001007
Which language is this ?

Sorry for being late. Anyways, It's C; I think you can tell from the void function parameter.

Ali-Ayed / FREE PALESTINE 🇵🇸 Автор вопроса
Sahand 🏔️
In short, char* cannot be changed. It's a const.

Really? But, let's be real, It's really confusing why const char *str can be changed.

Ali-Ayed / FREE PALESTINE 🇵🇸 Автор вопроса
Manav | avoid unnecessary messaging me
Extending what Sahand said, in C char* ptr = <str...

Yeah, but why I can modify it although it's const char* as shown in the previous message.

Ali Ayed / FREE PALESTINE 🇵🇸
screenshot Really? But, let's be real, It's really confusing ...

You're assigning to a pointer to const data. The pointer itself is not const there. For example *message = is not possible.

Ali-Ayed / FREE PALESTINE 🇵🇸 Автор вопроса
Azadi
You're assigning to a pointer to const data. The p...

Oh yeah. Now I figured it out. Thank y'all for helping.

Ali Ayed / FREE PALESTINE 🇵🇸
screenshot Really? But, let's be real, It's really confusing ...

It is fully legal make a const ptr , point to another address. You just can't change the value of the content that it points to.

Ali-Ayed / FREE PALESTINE 🇵🇸 Автор вопроса
Sahand 🏔️
It is fully legal make a const ptr , point to anot...

Yup, you're right. I get a segmentation fault when I tried to change a single character.

Sahand 🏔️
In short, char* cannot be changed. It's a const.

char* just like any other regular pointer can be changed.

Похожие вопросы

Обсуждают сегодня

30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
Also, why can’t the community have a vote/ say when it comes to initiatives like buybacks. Isn’t the point of crypto decentralisation? Don’t we deserve input as long term supp...
👨🏽‍🦰
13
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
16
any reference of this implementation?
BitBuddha
29
Hi guys, any problem with Pulsebrige? Trying to transfer from wETH to ETH. First it tells me to connect my metamask "through mobile app" not desktop. Then I did and confirmed ...
Snowflakecrypto
13
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
Карта сайта