\Device\NUL
That's why in C++11 you need to define const char * not char *
Anonymous
But the question is why I can’t rewrite this string literal, but can read
Look at this https://stackoverflow.com/a/11399790 You cannot write because the memory it points to is immutable. But that doesn't mean you cannot use malloc and point to a different memory address.
\Device\NUL
And that's a good habit since Standard C doesn't force to declare pointer char as const
Anonymous
Ok, then what difference between these two lines: char* ptr = “aaa”; const char* ptr = “aaa”; From both I can read, to both I can’t write
The difference is that in the first case, you can point ptr to something else entirely, that's not possible in the second case.
olli
The difference is that in the first case, you can point ptr to something else entirely, that's not possible in the second case.
you can re-assign the pointer, you can't reassign this one char * const ptr = "aaa"; const char * a; => declare a as pointer to const char char * const a; => declare a as const pointer to cha
%Nikita
Ok, and then const pointer means that I can’t change the value, by this address, or address itself?
olli
Ok, and then const pointer means that I can’t change the value, by this address, or address itself?
if you have a pointer to const you cannot change the content it is pointing to. If you have a const pointer you cannot change what it is pointing to. If you have a const pointer to const you can't change either. char S[] = "Hello"; { const char * const F = S; // F = "1"; // illegal, const pointer // F[0] = '1'; // illegal, pointer to const } { char * const F = S; // F = "1"; // illegal, const pointer F[0] = '1'; // legal } { const char * F = S; F = "1"; // legal // F[0] = '1'; // illegal, pointer to const }
Anonymous
Thanks, I now understand, that is really interesting declaration: char * const a;
Forget about strings for a while, the whole pooling thing makes it confusing. int a = 10, b = 20; int* const p1 = &a; // p1 = &b; (error ) *p1 = 42; const int* p2 = &a; p2 = &b; //*p2 = 42; (error) Take a look
Clash
string s1{"110"}, s2; // cin>>s1; string::reverse_iterator it; for (it = s1.rbegin(); it != s1.rend(); it++) { int i = 0; s2[i] = char(*it); i++; } why s2 doesn't make the copy of s1
Alex
Hi guys question i'm creating a program in c ++ with functions and i would need a function that compares me the mean of vectors and The function must compare the mean of vector A with vector B and print me a message if the difference between A and B is less than a maximum of 2 points Same between A and C Same between C and B
Pavel
string s1{"110"}, s2; // cin>>s1; string::reverse_iterator it; for (it = s1.rbegin(); it != s1.rend(); it++) { int i = 0; s2[i] = char(*it); i++; } why s2 doesn't make the copy of s1
1. It looks like access out of bounds, you need to do resize s2 first, to make it allocate big enough buffer 2. You need to have int i = 0 outside of your loop, otherwise it's always 0
Clash
#include <iostream> #include <string> using namespace std; int main() { string s1{"110"}, s2; s2.resize(s1.length()); int j = 0; for (auto i = s1.rbegin(); i != s1.rend(); i++) { if (*i) s2[j] = '1'; else s2[j] = '0'; j++; } cout << s2 << endl; } here s2 has to print 011 but it's printing 111...
Rodrigo
thanks to the other answers as well
Pavel
Or in your case you can just do s2[j] = *i; without the if
Vlad
There's no leakage
Anonymous
Hi everyone I want to write a simple program that I got into trouble and need help because I am a novice 🙂 I am going to write a program that the user enters from character A, for example, to character C, and then the ASCII Code program displays them, for example: ASCII Code A: 65 ASCII Code B: 66 ASCII Code C: 67
Anonymous
#include <stdio.h> int main(){ for(char i = 'A';i <='C';i++){ printf("ASCII Code %c: " , i); printf("%d \n" , i); } return 0; } output: ASCII Code A: 65 ASCII Code B: 66 ASCII Code C: 67 Now I have written this code myself, but instead of entering the characters in the loop myself, I intend to enter the user characters in the loop
Nikit
@Packer000 what you want to print as output
Nikit
?
Anonymous
?
For example: ASCII Code A: 65 ASCII Code B: 66 ASCII Code C: 67
NIGHT
What will be in ans1, ans2 after: unsigned int a=5, b=0, c=11; unsigned int ans1=!a||b&&c; unsigned int ans2=!a||b&c; a) 1, 5 b) 7, 0 c) 0, 1 d) 11, 5 e) 1, 0 f) 0, 0
NIGHT
Can someone tell me what is the correct answer
Nikit
Then program is right
NIGHT
0 0
Can you please tell me how did you know? Because I have a zero knowledge in C++ and tomorrow I have a exam
Hanz
What?
NIGHT
What?
Can you help me?
Hanz
Can you help me?
You need to learn operators, that's it.
NIGHT
You need to learn operators, that's it.
But for now can you solve 5 questions for me please
AmR
I need some help with WInAPI Can Any one help me ?
S
Learning turbo debugger higher version tdstrip says file has bad symbole table Book says if i update files using touch will solve problem But i cant use it in dosbox I found in internet i should use Copy /b Command but it emptys files May sombody help about this
S
I owe an apologize because i first forwarded my question from other group but it failed then i tried typing because of that my messages were several and small
Xi
Hello guys could someone please help me w/ flood character enable. I’m trying to program my Tivaware DK-TM4C123G
tkali
Write and test the following function that removes items from an array: void removeAll(float a[], int& n, float x); The function removes all occurrences of x among the first n elements of the array a and decreases the value of n by the number removed.
S
Hi, this software seems to be pretty old, not sure if someone here can help with it. Is there an option to use something more up to date?
Thanks i want to learn assembly and debugging and i dont know about other options About it this is my problem, How to update ( time stamps) to check if it solves problem And learn smthing new about this problem My goal is to know how computers work and try to manipulate it in with exact command to details of hardware If you may introduce other options please I will be thankful
Pavel
Thanks i want to learn assembly and debugging and i dont know about other options About it this is my problem, How to update ( time stamps) to check if it solves problem And learn smthing new about this problem My goal is to know how computers work and try to manipulate it in with exact command to details of hardware If you may introduce other options please I will be thankful
So you're using TASM? I don't know much good alternatives since I haven't written in assembly for a decade, but here's a list of different assemblers for reference https://en.m.wikipedia.org/wiki/Comparison_of_assemblers I think I used MASM, but I don't remember if it was difficult to connect a debugger to it.
\Device\NUL
Asaembly itself
Assembly is not portable, you can't run Sys V Assembly on Windows, x86-64 on i386. It depends on Arch and Kernel
S
Then i want to learn both
\Device\NUL
Then i want to learn both
Are you sure about that ?
\Device\NUL
Different kernels has different syscalls
M
Hi..I don't know which compiler will be appropriate for my code blocks,I need help to access link of download... anyone can help me?🙏🙏
\Device\NUL
Yea
So what assembly you want to learn ? There are tons of youtube video
S
My question is how to update time stamp I want to learn assembly in pc and simple Ics I think learning one will help in others
S
Which one iwill need now independent from os
\Device\NUL
Which one iwill need now independent from os
Gah, i can't help you. ask in this group https://t.me/assemblybr
Anonymous
Can anyone share good resources for learning STL
Anonymous
Mainly for CP
M
Thanks 👍
Anonymous
What's the difference between? map. insert({2,30}); map. insert(make_pair(5,6));
Anonymous
I remember that {} is an implicit declaration of pair
Pavel
I remember that {} is an implicit declaration of pair
not only for pair, for any implicit (not marked as explicit) constructor https://ideone.com/ZvW8va
Anonymous
what is the type of map?
map<int, int> map;
Anonymous
I remember that {} is an implicit declaration of pair
So this "pair" can have more than 2 members too