coal
i'm reading more about this
coal
thank you for clearing my doubts
Leovan
int a[2][3] = ...; What type of a pointer on a multidimensional array (a)? It's not int *, because i need to cast it first, for example: *((int *)a + i*3 + j) = a[i][j] typeid says: A2_A3_i
Anonymous
int a[2][3] = ...; What type of a pointer on a multidimensional array (a)? It's not int *, because i need to cast it first, for example: *((int *)a + i*3 + j) = a[i][j] typeid says: A2_A3_i
int a[2][3] = {0}; int (*ptr)[3] = a; //To access a[0][0] (*ptr)[0] (or) *((*ptr)+0) //To access a[1][2] (*(ptr+1))[2] (or) *((*(ptr+1))+2) Using typedefs or using aliases would make these more friendly but hope you get the general idea
Leovan
int a[2][3] = {0}; int (*ptr)[3] = a; //To access a[0][0] (*ptr)[0] (or) *((*ptr)+0) //To access a[1][2] (*(ptr+1))[2] (or) *((*(ptr+1))+2) Using typedefs or using aliases would make these more friendly but hope you get the general idea
Hm, so it's two different ways to work with arrays? We can use pointer (a) like in one dimensional array and move it: *((int *)a + i*3 + j) = a[i][j] And we can use a like pointer on array of size 3, like pointer on line, and move to another lines by inc/dec? int (*ptr)[3] = a; *(*(ptr+i)+j) = a[i][j] So a its pointer of pointers.
Fuck The
How do I validate that the binary code of my compiled C or C++ application was not modified by some third party before sending data to a remote server?
coal
you want to check integrity
coal
cant you just generate a sha hash and then compare it
Anonymous
Ptr looks like 3 pointers .. (array of pointers) pointing to a[0][0].. why not int **ptr.? To make things cleaner i guess?
No. It is not 3 pointers. It is a pointer to an array of 3 elements. int** pointer is a pointer to an int* pointer. But here you need a pointer to an array of 3 elements.
Fuck The
cant you just generate a sha hash and then compare it
You mean before sending a request to the server from my distributed app residing on the user’s computer, I will first calculate on the user’s computer the hash value generated from the app’s binary code and then send that code along with the request’s data to the server for validation and on the server side I will compare the generated hash on the user’s computer that was just sent with the hash that was already pregenerated for my original app and is already stored on my server?
Fuck The
cant you just generate a sha hash and then compare it
I am asking just for validating that I have understood the method correctly, Thanks
coal
the original binary and the user's binary
coal
simple integrity check principle
Hsn
No. It is not 3 pointers. It is a pointer to an array of 3 elements. int** pointer is a pointer to an int* pointer. But here you need a pointer to an array of 3 elements.
How does compiler make that .. If the address is 32bit.. That pointer would be (32bit size) and compiler inject code of (3) everywhere we use that pointer? ..
Anonymous
How does compiler make that .. If the address is 32bit.. That pointer would be (32bit size) and compiler inject code of (3) everywhere we use that pointer? ..
A pointer to an array of 3 integers is nothing different from a regular pointer as far as the address to which it points is concerned. Where they differ is how pointer arithmetic applies to them. If you have two pointers like int* ptr and int (*ptr1)[3] the first one is a pointer to int and the second one is a pointer to an array of 3 ints So when you do ++ptr, the compiler knows it is a pointer to an int and hence it will advance it by sizeof(int) bytes But when you do ++ptr1, the compiler knows it is a pointer to an array of 3 ints and will advance it by 3*sizeof(int) bytes.
Hsn
So its the compiler who injects code of +3 ..
Anonymous
Sorry if completely unrelated but what are good resources for self-learning algorithms and data structures, preferably using c/c++?
Hsn
Make more sense because it would be disaster if it was array of pointers Imagine how much wasted memory for Char arr2D[1000][2]; Char (*ptr)[1000];
Ashwani
#include<iostream> using namespace std; class B{     public:     virtual void s(){         cout<<"In base"<<endl;     } }; class D{     public:     void s(){         cout<<"In derived"<<endl;     } }; int main(){     B *bptr;     D d;     bptr=&d;     bptr->s(); }
Hsn
https://youtube.com/playlist?list=PLBlnK6fEyqRhX6r2uhhlubuF5QextdCSM https://youtu.be/nvRkFi8rbOM https://youtube.com/c/EricOMeehan I find these are good for a start in c. TheCherno is good c++ channel (i didnt see data struct or algo there).
Anonymous
What about new dev c++ versions?
Anonymous
Such as embarcadero dev c++
Anonymous
Such as embarcadero dev c++
That is good and modern. You can use it.
Ashwani
You forgot to derive D from B
Ok thanks I got it now
Fuck The
yeah compare two hashes
Thank you very much for the guidance
itsmanjeet
Hey, do anybody know the syntax for specialized template constructor Google is not in the mood to answer, I need something like Class Value { void* buffer; MyType type; template<typename T> Value(T t) {} } So that if pass any int, long short or any integral value it will go for the constructor of int type If i pass any float, double value that it will go for construct of float typw
Igor🇺🇦
Hey, do anybody know the syntax for specialized template constructor Google is not in the mood to answer, I need something like Class Value { void* buffer; MyType type; template<typename T> Value(T t) {} } So that if pass any int, long short or any integral value it will go for the constructor of int type If i pass any float, double value that it will go for construct of float typw
Try using https://en.cppreference.com/w/cpp/header/type_traits with syntax something like https://stackoverflow.com/questions/18364417/template-struct-specialization-for-integral-real-types Or, if you're using C++20, try concept https://en.cppreference.com/w/cpp/concepts/integral
sundeep
#include <bits/stdc++.h> using namespace std; vector<int> vectfunc(int arr[],int tn){ map<int,int> mp; vector<int> v; for(int i=0;i<tn;i++){ mp[arr[i]]++; } map<int,int> ::iterator it=mp.begin(); for(;it!=mp.end();it++){ if((it->second)>=2){ v.push_back((it->first)); } } return v; } int main() { // your code goes here int n1,n2,n3;cin>>n1>>n2>>n3; int tn=n1+n2+n3; int arr[tn]; for(int i=0;i<tn;i++){ cin>>arr[i]; } vector<int> vect=vectfunc(arr,tn); for(int i=0;i<tn;i++){ cout<<vect[i]<<endl; } return 0; }
sundeep
Can anyone say . Whats wrong in my code
数学の恋人
class Instruction { protected: type::byte opcode; type::byte cycles; std::string name; public: // constructor Instruction(type::byte ins_opcode, std::string ins_name, type::byte ins_cycles) : opcode{ins_opcode}, cycles{ins_cycles}, name{std::move(ins_name)} {}; }; Why does compiler warn me about opcode, cycles and name being protected?, why do we have those access specifiers if I can't have members as those? Compared to above.... class Instruction { private: type::byte opcode; type::byte cycles; std::string name; public: // constructor Instruction(type::byte ins_opcode, std::string ins_name, type::byte ins_cycles) : opcode{ins_opcode}, cycles{ins_cycles}, name{std::move(ins_name)} {}; inline type::byte get_opcode() const { return opcode; } inline type::byte get_cycles() const { return cycles; } }; Is this way more preferable and better/safer/whatever?
sundeep
for(int i=0;i<tn;i++){ cout<<vect[i]<<endl; }
sundeep
Got error
sundeep
In for loop . I should use vect.size instead of tn
sundeep
If I send question link here . It's getting deleted
Anshul
I'm not able to understand the intuition behind Euclid's algorithm. I.e. gcd(a,b)=gcd(b,a%b) Can anyone help me understand the intuition
Anonymous
I'm not able to understand the intuition behind Euclid's algorithm. I.e. gcd(a,b)=gcd(b,a%b) Can anyone help me understand the intuition
Let k be the GCD of a and b. Assume a > b a can be written as p*b + q where q is a%b Now k should divide both b and q. If k is a divisor of b but not of q then k can't be a divisor of (p*b + q) Only if that is the case can k be a divisor of both a and b. So k is the GCD of b and q which is the intuition behind Euclid's algorithm
Melbgm
Can't I write like this? gives an unresolved exclude error
Melbgm
didn't copy the functions
Pavel
the code that you pasted looks fine, maybe the error in other parts of the code? Did you implement all the functions and declared them before main?
Melbgm
Yes i think so
Anonymous
folks, how to learn gcc effectively
Anonymous
I feel it hard
Syed
hello
Syed
anybody knows how to build symbol table in c++
S__R
You taking integer value from user and using char in switch
Prince Fine
Welcome But don't forget to Read the rules
coal
folks, how to learn gcc effectively
learn the compiler collection?
Anonymous
I use Arch
no, just compile
You mean compiler arguments?
Anonymous
You mean compiler arguments?
yeah, I found a video, already learned it
I use Arch
yeah, I found a video, already learned it
There are a few arguments you will usually use and need to remember. The rest can be always googled
Anonymous
yeah
Mostakim
how to sort 3numbers in ascending order? can anyone suggest a easy method for do this?
tb
/get cppbookguide
Abdelrhman
I need some help
Abdelrhman
Can anyone help me in c++ program mming
Abdelrhman
?
Abdelrhman
Programming
Anonymous
Making windows apps using managed C++ is an option but it is nothing as friendly as C#. Know the domain you are going to be working on. If it is something that involves heavy GUI work on Windows then learning C# is a good investment. You have other alternatives but C# is the best out there and as a language C# is much better designed when compared to C++ (managed or otherwise)