Anonymous
how can i call a function during runtime? for example i run the code and
input show then output an integer
%Nikita
BESHO
Anonymous
Danila White
Hello there, can someone explain how line 27 works in this code (https://gist.github.com/smthinthewayy/8b130b64b033e51e6cad8e640ee70ebf).
Danila White
eg log(123) = 2 * log(10) + 0 * log(2) + log(0.229)
Danila White
how?))
klimi
it just multiplies and adds some numbers?
Danila White
it works perfectly, but I don't understand how, what is this property?
BLOW TV
Please what's are the variables in c programming
Can only get 5 from net
Dinuka
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
int x,y,z;
cout <<"Input Number 1: ";
cin >> x;
cout <<"Input Number 2: ";
cin >> y;
cout <<"Input Number 3: ";
cin >> z;
if (x=y=z){
cout<<"all 3 equal";
} else
cout<<"not all equal";
return 0;
}
What is wrong with this code? I'm getting same output
\Device\NUL
Anonymous
\Device\NUL
\Device\NUL
You can define variables later, not at declaration time
\Device\NUL
Use &&
\Device\NUL
x == y later will become 0 or 1 (result of comparing x and y), and then become 0 == z or 1 == z
Dinuka
\Device\NUL
& and && is different
\Device\NUL
& is AND bitwise operator
\Device\NUL
Now days people ignoring compiler message and asking in the group instead
Pavel
I like how you ask to input 1, 2 and 3, compare them as x, y and z, and output to user as A, B and C 😆
\Device\NUL
Anonymous
What is :: scop resolution operator in c++
Prakhar
#res
Anonymous
eg log(123) = 2 * log(10) + 0 * log(2) + log(0.229)
Errm it is not.
According to your equation log(123) = log(22.9) which it is definitely not. This equation is not correct. Either you have made a mistake somewhere or you misunderstood what they taught you at school.
Danila White
Danila White
log(d) is found using a Taylor series expanded around x = 1
x = 10^n * 2^m * d
log(x) = n * log(10) + m * log(2) + log(d)
But base 10 is useless, we have numbers stored as order + mantissa, and we need to change the order keeping mantissa to get in the range from 0 to 1
Danila White
result: log(x) = m * log(2) + log(x - 1)
Anonymous
What is :: scop resolution operator in c++
There are different kinds of scopes in C++ (scope is a region in which a name is valid). Ex - Namespace scope, class scope, block scope, global scope etc etc.
The scope resolution operator is used to identify names within a class scope, a namespace scope, global scope or enumeration scope.
For ex a global variable a can be identified using ::a. A name b in namespace scope N can be identified by N::b. A static name c in Class C can be identified as C::c.
The name before :: identifies the scope. If it is empty it is assumed that you are referring to a name in global scope.
Danila White
Pavel
I think it's the only proper way, why doesn't it suit you?
Pavel
I guess it will be just if-elseif-else as in the example here
https://en.cppreference.com/w/cpp/utility/any/any_cast
There's no enum or similar thing underneath that would speed that up (because it can literally be any type, including any user-defined type).
Pavel
You can also match by type_info, like in the example by the link below, its better when you have many possible variants
https://en.cppreference.com/w/cpp/utility/any/type
Pavel
But you anyway have to do any_cast in the end
.
what is the difference between <cstring> and <string.h>?
Naol D
Why is this not working?
.
.
.
char *ptr = "text"";
*(ptr + 1) = 'o';
why do i get a segmentation fault ?
Alviro Iskandar
Alviro Iskandar
you probably want this:
char mut[] = "text";
char *ptr = mut;
*(ptr + 1) = 'o';
Alviro Iskandar
that mut variable is mutable, so you can do a write dereference
Alviro Iskandar
but char *ptr = "text" is read only (the string literal "text" can't be changed), dereference only works for reading operation
Hussein
conko
conko
conko
I'm talking about C++ behavior, where the "historical problem" is exactly from C.
Hussein
this hurts as a C programmer 😂
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Hi guys, I have a shared memory question: so, Imagine you have a Process that creates
A) A vector of N shared memoryes;
B) N threads;
Now, since the threads share the generator Process address space, I think it's safe to assume that, if I attach (with shmat) all the N shared memories in the code of the generator process, of course storing the address, then all the threads will be able to use this address in order to read/write information from/on it, right?
Because, right now, I have something like this:
PROCESS FUNCTION:
Creates N-entry-shared memory vector with shmget (so the entry will be like: shmID0| shmID1 | ... | shmIDN-1);
Attaches its address space only to the first one (for reasons due to the code itself);
generates N threads;
THREAD FUNCTION:
Attaches itself on the shared memory he is interested in;
But this is equivalent to the first thing I said, right? Even worst, if I attach the first shared memory (between generator process and first thread) both in process code and thread code, I would be attaching this thing twice, right?
Thank you!
Note: for those interested, I solved the problem and the solution is: it makes no sense to use shared memory with threads, just map k*N pages on the generators address space and pass the address to the page to the threads
\Device\NUL
Alviro Iskandar
It it lived on .rodata ? 🤔
it's not the const char * that places the data, but char *p assigned with a string literal
const char *p doesn't always mean it points to .rodata, it can live everywhere
const char *p = malloc(100) is fine too
Alviro Iskandar
void fx() {
char x[] = "hello";
}
this lives on the stack
Alviro Iskandar
but char *p = "hello"; is immutable, that's why it's read only
Alviro Iskandar
Distac_221
anyone?
Alviro Iskandar
the code is horrible and messed up, you have random indentations all over the place
please fix that first before asking people to review your code, at least make it more human readable
don't expect to get help if you don't help us to even properly read your code
Zaur
https://linkode.org/#8fANgCGZAGRvIVmJIFULc6
Distac_221
Anonymous
https://linkode.org/#8fANgCGZAGRvIVmJIFULc6
Why are you calling pthread_create and pthread_join again in the inner loop?
You don't need two loops here. You just need the outer loop.
Printing to the console from different threads requires synchronisation between the threads. If you don't synchronize, the outputs will all be interleaved. So use something like a mutex to ensure that only one thread is writing to the console at a time.
In the task method, the thread_num variable has a value between 1 and 5. Inside this method, lock the mutex and then use a loop to print as many stars as is the value of thread_num variable. Unlock the mutex after printing the stars.
Alviro Iskandar
Anonymous
Ammar
Anonymous
Anonymous
How can use in class
You can use the scope operator in classes to access typedefs/aliases, inner classes, static members et al.
Sylvester Lim
string choice = "y";
while (choice.compare("y") == 0)
{ something something}
cout << "\nPlay again (y/n): ";
getline(cin, choice);
can someone explain to me how exactly is string.compare is being used here? to break out of the loop, it has to be false which means not equal to 0, but how does cin y make the loop be 0 (and continues looping again) ?
Anonymous
How to make a calculator which can perform operations more than 2 numbers?
Eg: 2+7*7-8
If anybody have example project Please share
klimi
Anonymous
klimi
And I guess you want to have operation priorities as well? Multiplication goes before addition etc?
Anonymous
klimi
Then you will need to parse by these priorities eg. Search for *, then parse left and right number and then add them together. You can pre parse this by splitting it into some structure of each element
Anonymous