Дмитрий
string* ptrvalue = new string[2]; ptrvalue[0] = "bool"; ptrvalue[1] = "char"; for (int i = 0; i < 2; i++) { cout << sizeof(ptrvalue[i]); } This is how I always define str and I need bool, int
Nomid Íkorni-Sciurus
Nomid Íkorni-Sciurus
+
Short answer: you can't do that
Nomid Íkorni-Sciurus
Long answer: you don't want to do that because it would be pretty inconsistent.
Nomid Íkorni-Sciurus
You could technically compare strings or create a map<string, string> but you shouldn't
江流儿
#include<iostream> using namespace std; int main() { cout << 2.5F * 2U + 3LU * 5U - ‘b’<< endl; cout<<sizeof (2.5F * 2U + 3LU * 5U - ‘b’) return 0; }
\Device\NUL
江流儿
The first cout ('b')
klimi
How to fix this code
by "fix" you mean what?
\Device\NUL
Ludovic 'Archivist'
How to fix this code
Your code carries no intent, what are you even trying to achieve?
klimi
the first fix would be to correct the `'` symbol in ‘b’
江流儿
cout << 2.5F * 2U + 3LU * 5U - ‘b’<< endl;
\Device\NUL
Confused nick young
klimi
I mean this one
still the same fix
江流儿
Ok got you
klimi
next fix would be to stop using that namespace, then maybe commenting what that code is even supposed to do.... and maybe not using endl just for one line if you are ending the program anyway
klimi
and idk... what you want to do with it...
\Device\NUL
\Device\NUL
x %= y is same as x = x % y
Suraj
modulo operator
Oh, i got it
Anonymous
x %= y is same as x = x % y
数学の恋人
arr = realloc(arr, sizeof(*arr) * (--n)); Is there anything wrong in this? I must work as expected right? I am just shrinking the memory allocated by one unit of whatever datatype a *(arr + i) is
Alviro Iskandar
arr = realloc(arr, sizeof(*arr) * (--n)); Is there anything wrong in this? I must work as expected right? I am just shrinking the memory allocated by one unit of whatever datatype a *(arr + i) is
From the size itself, I don't see something weird, but who knows?, the code is incomplete, can't review what might go wrong here. nit: realloc() should use a temporary variable to handle the failure case, otherwise you're leaking memory when the allocation fails, because you lose the old pointer. void *tmp; tmp = realloc(arr, new_size); if (!tmp) { // handle failure // arr must be freed somewhere // tmp is null return ...; } arr = tmp; // arr is resized here..
Alviro Iskandar
why void *tmp instead of whatever the type of arr is
Better be whatever the type is, but void * can be assigned to any other pointer types without cast (in C). It's not an excuse to use void *, I just don't know what the type of arr.
数学の恋人
Thanks bud
不要惹胖虎
How to invoke python script by c++ ? Please give me some examples. Thanks 👍
klimi
How to invoke python script by c++ ? Please give me some examples. Thanks 👍
like you want to create python module or... you want to literally run python process?
神 ꜰʟᴀꜰꜰʏ
guys, what is the error? int x = 5; int *px = *(x-1); can't get the value (x-1) or what?
%Nikita
guys, what is the error? int x = 5; int *px = *(x-1); can't get the value (x-1) or what?
What are you trying to do? Compiler thinks you want to take value from address 4.
神 ꜰʟᴀꜰꜰʏ
this is a task, we need to find mistakes and fix them
%Nikita
this is a task, we need to find mistakes and fix them
What program should do? Get value x-1?
%Nikita
Try this int x = 5, *px = *(&x)-1; Still don’t understand why do you need pointer for this :)
Anonymous
hi can anyone explain reference variables to me?
coal
What program should do? Get value x-1?
set pointer address to x-1
coal
he asked me as well, he wants to know what the error is in that code
coal
it's a segmentation fault
%Nikita
set pointer address to x-1
Oh that thing. But it will be ub
Anonymous
%Nikita
Isn't this wrong? Because you're storing int in int*
Yes, but physically it is not wrong. Integer value is same size as integer pointer, and integer pointer is a memory cell too. We can use it as a common integer value, or store addresses in integer type.
%Nikita
1. They might not be the same size 2. It's an error without explicit casting 3. Why not just do x-1 then?
1. Agree, I told about most popular x86 platform 2. I am using C, and I haven’t got any error. Maybe something wrong with my compiler? 3. I don’t know. I thought this guy want to calculate x-1 using pointer’s operations and just put it into pointer.
%Nikita
Ah it's only an error in C++. In C, it just shows a warning.
Thank you! I thought it is something wrong with my compiler :) It is because C++ is more high level language
Anonymous
Thanks so much
\Device\NUL
Yes, but physically it is not wrong. Integer value is same size as integer pointer, and integer pointer is a memory cell too. We can use it as a common integer value, or store addresses in integer type.
int on x64 system is 32 bit, while pointer on x64 system is 64 bit You maybe got overflow, The only way to store address in integer is in size_t. Or using x32 ABI that using 32 pointer but still use x64 calling convention Edit : Lol, i misread your words
不要惹胖虎
like you want to create python module or... you want to literally run python process?
i plan to invoke python+echarts with c++ in order to display colorful charts
不要惹胖虎
Cool! That's what I want.
不要惹胖虎
yeah
Metacall is a charge?
Hima
vector<string>ss; for(int i=0;i<n;i++) { cin.ignore(); string s; getline(cin,s); ss.push_back(s); } not working for input: n=2 4 5 why 5 is not being pushed to the vector?
Thomas
Hi there. Wondering if anyone has any ideas about this I've been tasked with writing a file in one program and then reading it using another I have both programs working and sharing a file but after I would like to output a message that the file has no more characters in it when I'm reading it back out Is there a way to do this using the read() system call? I've had a look on Google but struggling to find a solution 👍
Abdulwahab
can visual basic 6.0 code work on visual basic 2013? Please someone should help me out.
Thomas
Abdulwahab
I am afraid you have not messaged the right group
Let's wait and see. Perhaps someone might answer me.
Anonymous
can visual basic 6.0 code work on visual basic 2013? Please someone should help me out.
This is not a relevant question for this group. Please refrain from asking questions unrelated to the group. The answer to your question is no. VB6 requires a VB6 runtime while VB.Net requires the .Net CLR. The runtime libraries are different for both and are not compatible.
klimi
Let's wait and see. Perhaps someone might answer me.
I am afraid you haven't read the rules... i would really appreciate you reading it
Null
hi
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Hi guys, I am looking for some advice here cause I really don't know how to move: I am asked to fill a possibily very huge matrix with 0s and 1s. The problem is, the more this matrix grows, the more memory those 1s and 0s will occupy. So the first thing I said was "fine, I shall use unsigned shorts in order to represent 0s and 1s, as a whole int seems unnecessary"; then I thought "what about actually creating a binary number, which takes only 1 bit in memory?"... this way, I would optimize the memory occupation of the matrix, but I don't know how to do that. Do you have any suggestions? Sadly, I do not have any code, because other than using a bit mask I haven't come up with anything useful (note, I just started C programming, therefore I am no real expert, but feel free to give me, if you are willing to, as much complex code as you want, I'll try to figure it out by myself later on)... thanks!
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
1) C; 2) Yes, only 1s and 0s; 3) No, given a certain dimension (it's a squared matrix) it remains the same through the runtime