Lucas
Can anyone recommend c++ books?
Soubarna
How do I interpret the arrow operator (->) in C/C++ when three or more operands are involved? For example, if a, b and c are the operands, how do you interpret a->b->c?
Pavel
How do I interpret the arrow operator (->) in C/C++ when three or more operands are involved? For example, if a, b and c are the operands, how do you interpret a->b->c?
Object pointed by a stores b as pointer, and object pointed by b stores c as pointer. So we dereference a, then get b from the object, dereference it and get c from that object.
Pavel
If it was a function call a->foo()->bar() Then it could be that foo() returns a pointer to something, sometimes it can return pointer to a again, it's called chaining (if I'm not mistaken)
Pavel
Code like this std::cout << 1 << 2; implemented using chaining basically under the hood
Soubarna
Thanks a lot @gameraccoon
Void
#include <stdio.h> int main() { long int s,x=1; int n,i; s=0; for(n=1;n<20;n++) { for(i=n;i>0;i--) { x=x*i; } s=s+x; x=1; } printf("%d",s); return 0; }
Void
Guys why do I get a negative result
You know me
Guys why do I get a negative result
May be overflow. Check by reducing the number.
Void
May be overflow. Check by reducing the number.
When n = 13, the result starts to become negative
You know me
When n = 13, the result starts to become negative
You are overflowing the limit of data type used. So either used a data type with more size or use number upto 13.
Void
#include <stdio.h> int main() { int i,j; long int sum,n; sum=0; for(i=1;i<=20;i++) { n=1; for(j=1;j<=i;j++) { n=n*j; } sum=sum+n; } printf("%d",sum); return 0; }
Void
I wrote almost the same program and this time it worked.But what's the difference?
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
I guys! If I have a struct like this: struct node_t{ struct node_t *next; char *string; } Which represents a node in a list. And a node struct node_t *new; when I need to delete new, I'll have to save the current location this way: struct node_t *to_free= new; struct node_t *to_free; // Stuff free(to_free); ok, but is it right? In fact, we do have two more pointers inside the node: the pointer "next" to the next node in the list, and the char *. Do I need to free them too?
Shobi
finclude <type.h> /• loads file with predicate isdigit */ int lookahead; main() lookahead = getchar (); exprl): putchar ('\n'); /* adds trailing newline character */ expr () term(); while (1) if (lookahead == '+') { match('+'); term(); putchar ('+'); else if (lookahead == '-*) ( match ('-'); term(); putchar ('-'); ) else break: term ( ) if (isdigit (lookahead)) 1 putchar (lookahead); natch (lookahead); else error(); match(t) int t; if (lookahead *= t) lookahead = getchar (); else error (); ) error () printf ("syntax error\n"); /* print error nessage exit (1); then halt
You know me
I wrote almost the same program and this time it worked.But what's the difference?
In the second one variable is initialized to 1 just before the second loop starts, while in the first one it is initialized after the damage is done. I could be wrong but try it out.
Anonymous
How can I convert my C code to an apk from Android (i have made an program and want to conver it in an apk so that if someone will open that apk that program shows up) Because i need to share it as a presentation
Anonymous
How do I interpret the arrow operator (->) in C/C++ when three or more operands are involved? For example, if a, b and c are the operands, how do you interpret a->b->c?
Unless we see the definition of the types of a and b we can't say for sure. You see two operator-> arrows in the expression you showed but the compiler could have translated it into many more.
Khadija
Hi hope you are doing well Please i need help , anyone have a free course about complexity and big notation ? , or any sources that help me ✨? Thank you so much …
j. c o l e
hey
j. c o l e
who can help with discrete math?
You know me
I changed "n<20" to "n<=20" and it works😂
This is really weird. You are actually increasing 1 iteration.
Boom
https://hastebin.com/okotoyujez.cpp
Boom
https://hastebin.com/okotoyujez.cpp
this is a program for linked list , and i have only written it till add function, and I am getting Segmentation error in VS code and Dev C++ but the program runs fine in online compiler, Please help me to know why is this happening!
\Device\NUL
https://hastebin.com/okotoyujez.cpp
First, choice var is unitialized but you access the value. It's UB And, you already have NULL handler but It's useless
Boom
Give empty return ; to break void function
ok, should i do this in all void functions?
\Device\NUL
It's only free the memory allocated for struct, not allocated memory for the member
Gain
i want to find all the indexes of a element present in a array.. eg {1,2,3,2} if want to find index of 2 .. i should get {1,3} using find only gives me index 1
Pavel
i want to find all the indexes of a element present in a array.. eg {1,2,3,2} if want to find index of 2 .. i should get {1,3} using find only gives me index 1
You can run find in a while loop store iterator outside of the loop, first, initialize it with begig pass that iterator to search (so it searches from that iterator) save the result to that iterator, exit the loop when it points to end() You can also do search manually in a for loop, comparing each element
Pavel
thx
Also SO answer with code examples https://stackoverflow.com/questions/25846235/finding-the-indexes-of-all-occurrences-of-an-element-in-a-vector
Richard Luo 🐱
https://www.godbolt.org/z/4zPxzWz8W how to make this work?
Richard Luo 🐱
I dont understand why compiler think Type is not deducible
Anonymous
https://www.godbolt.org/z/4zPxzWz8W how to make this work?
Well think about it. The compiler says it is a non deducible context because given information about B, it is not possible for the compiler to deduce which A instantiation it is a part of. For ex I could have a specialization of A like this: class MyUDF{...}; template<> class A<int>{ public: using B = MyUDF; }; So suppose hash were called for MyUDF, how is the compiler supposed to deduce that Type is int based on that?
Richard Luo 🐱
What is it that you are trying to do?
For any specialization of A, B can be hash using this hasher
Anonymous
For any specialization of A, B can be hash using this hasher
That is not possible at all based on what I just said. template<> class A<Alpha>{ public: using B = MyUDF; }; template<> class A<Beta>{ public: using B = MyUDF; }; What would the compiler do? Again, am asking why you want to do this? Why should the parent class's template parameter control the hash template instantiation for a nested class? That just doesn't make sense at all forgetting that the compiler won't allow you to do it.
Anonymous
Because B uses Type and I want to create a std:unordered_set<B> inside A.
Just define a custom hash function object instead of specialising hash template and pass it in as the third template parameter argument for unordered_map
Boom
https://hastebin.com/okotoyujez.cpp
Boom
https://hastebin.com/okotoyujez.cpp
this is a program for linked list , and i have only written it till add function, and I am getting Segmentation error in VS code and Dev C++ but the program runs fine in online compiler, Please help me to know why is this happening!
Resul
Hi, How to Append a Char to a Char Pointer? char self = 'k'; char *word; word = (char*) malloc(12*sizeof(char));
Talula
Hi, How to Append a Char to a Char Pointer? char self = 'k'; char *word; word = (char*) malloc(12*sizeof(char));
Not the best of ideas if you haven't allocated memory for char *word... It might end up overwriting something else.
Talula
I changed post
The simplest way to do that is #include <stdio.h> int main() { char word[10]; word[0] = 'k'; word[1] = 'o'; word[2] = '\0'; printf("%s\r\n",word); return 0; }
Talula
I know that, I just want for Pointer
#include <stdio.h> int main() { char word[10]; word[0] = 'k'; word[1] = 'o'; word[2] = '\0'; char *wordp = word; wordp[2] = 'v'; wordp[3] = '\0'; printf("%s\r\n",wordp); return 0; }
Void
Can i set p=a[3][1] ? (p is a pointer)
Talula
Can i set p=a[3][1] ? (p is a pointer)
You can set pointer to anything.
Void
It shows [Error] invalid conversion from 'int' to 'int*' [-fpermissive]🥲
Anurag
I am new to c++, tried making a Class Array.. with sort, search and display methods. When i call method with reference to object it prints garbage values of array. I don't know much about how classes work in c++. https://pastebin.com/Hbdi5BHC
Anurag
Use double pointer
Can you help bro😭🙏🙏🙏
Daulet
Someone help pls
int A[size]; line is wrong. Correct: int* A = new int[size];
Anonymous
class sample{ int var; static int count; public: sample(int var):var(var){ // What exactly does this line do? could you please explain? cout<<"Count = "<<count<<endl; count++; } };
Anurag
int A[size]; line is wrong. Correct: int* A = new int[size];
Why is it wrong? Can i only declare array like this with actual parameter?
Anurag
int A[size]; line is wrong. Correct: int* A = new int[size];
🙏🙏🙏🙏🤩 thanx so much it works...only for this single line... Of code.. i changed and rewrote
Daulet
Why is it wrong? Can i only declare array like this with actual parameter?
I think in that case your memory allocated in stack. And after constructor method do work then that allocated memory frees (stack pops). New operator uses memory from heap
Void
int
Daulet
int
int* maybe
Daulet
int
But you need to use int**
Void
ohh yes int*
\Device\NUL
int
*(*(a + 3 * sizeof(int) + sizeof(int))