Daulet
Thanks Daulet, it worked
You're welcome =)
Koxy
Why did you declare the char rev function as char rev[222]??
Koxy
Why not char rev; or just as char [ ]?
Koxy
Why the [222]?
Daulet
Why the [222]?
static array.
Koxy
The 222 is a static array?, is that a constant?
Koxy
Okay does it have a meaning?, like probably does it mean we are duplicating a character?, or just a random constant?
Daulet
Just random constant. You can write any number.
In this case for him enough 222 char.
Koxy
Oh, okay. If [000] is written it won't work right?,
Koxy
Because its empty?
Koxy
But writing [222] means allocating 222 space for the characters?
Daulet
But writing [222] means allocating 222 space for the characters?
Bro its just simple code like you write in the school.
Daulet
Bro its just simple code like you write in the school.
If you write serious code then you use heap
Koxy
Oh thank you, I understand now.🙌
Hermann
how delete more elements in std::deque?. I try this but not work https://godbolt.org/z/44nPKseYr
Dm
how delete more elements in std::deque?. I try this but not work https://godbolt.org/z/44nPKseYr
First of all you can see that Delete is method not the function. I didn't see all the code but this part should look something like: s.Delete(v);
Dm
https://godbolt.org/z/Eav1xdGT5
Try to change Line 65: m_store.erase(std::find(m_store.begin(), m_store.end(), v[I]); Check names of variables because it's just the main idea I didn't remember the correct vaibales names
Hermann
👍🏿
jaebie
/perform the 2 of big three //create a new object under container cont1 container cont1; //create a new object cont2 and pass cont1 as input () container cont2(); //perform copy constructor //create a new object and use copy assignment operator =cont2 container cont3; //perform copy assignment operator cont3.operator=(); return 0; } I need to create all those task in the comment
jaebie
can someone help me
Anonymous
Sure
klimi
can someone help me
What are you struggling with?
jaebie
#include<iostream> using namespace std; class Triangle { public: double Area, Peri, Angle; void Area_Tri(double h,double b) { height = h; base = b; Area = ((b*h)*(0.5)); } void Peri_Tri(double j, double b, double m) { side1 = j; side2 = b; side3 = m; Peri = j+b+m; } void Angle_Tri(double ang) { if(ang<90) std::cout<<"The triangle is an acute-angled."; if(ang==90) std::cout<<"The triangle is a right-angled."; if(ang>90) std::cout<<"The triangle is an obtuse-angled."; } private: double height,base,side1,side2,side3; }; int main() { Triangle triangle1; triangle1.Area_Tri(4.3,6.5); std::cout<<"The area of the triangle is " << triangle1.Area<<"."<<::endl; triangle1.Peri_Tri(5,6,7); std::cout<<"The perimeter of the triangle is "<< triangle1.Peri<<"."<<::endl; triangle1.Angle_Tri(23); std::cout<< triangle1.Angle<<"."; return 0; } This is my program, once I tried to run it, there's a random scientific notation(?) at the end of my program
jaebie
how should I fix this one
klimi
how should I fix this one
You are not setting anything in Ange_tri. You are just housing side effects with std cout. This is why garbage is displayed.
jaebie
what should I put?
Talula
sushi
can someone help me to create a function that will take Booleab values and display the resukt of all logicak operatuons the return true if it was a success?
Nana
Hello, pls how can I delete items in array or vectors at a specific index
klimi
Hello, pls how can I delete items in array or vectors at a specific index
https://en.cppreference.com/w/cpp/container/vector/erase beware of bad time complexity
Notaxmar
#include<stdio.h> #include<stdlib.h> struct Student{ char name[50]; char major[50]; int age; double gpa; }; int main () { struct Student student1; student1.age = 22; student1.gpa = 3.1; strcpy( student1.name, "Jim"); strcpy( student1.major, "Business" ); struct Student student2; student2.age = 21; student2.gpa = 2.9; strcpy( student2.name, "Peter"); strcpy( student2.major, "Art"); printf("%f", student2.gpa); printf("%s", student2.name); return 0; }
Notaxmar
/storage/emulated/0/Can programme files/structs.cxx:17:5: error: use of undeclared identifier 'strcpy' strcpy( student1.name, "Jim"); ^ /storage/emulated/0/Can programme files/structs.cxx:18:5: error: use of undeclared identifier 'strcpy' strcpy( student1.major, "Business" ); ^ /storage/emulated/0/Can programme files/structs.cxx:22:5: error: use of undeclared identifier 'strcpy' strcpy( student2.name, "Peter"); ^ /storage/emulated/0/Can programme files/structs.cxx:23:5: error: use of undeclared identifier 'strcpy' strcpy( student2.major, "Art"); ^ 4 errors generated.
Notaxmar
OV
hi
klimi
hi
nohello.net
Iti..jaiswal
#includestudio.h>
Nomid Íkorni-Sciurus
i wonder why most compilers does'nt recommend to include the required library
because to the compilers, free identifiers are just undefined procedures
Nomid Íkorni-Sciurus
and you might actually NOT want to use the default library
Back Track
does anyone how to get some data from a bin file and then push that retrieved data into a struct? any link to tutorials or websites that explained this appreciated
ɛ n h ᴀ n c ɛ ґ 🧟‍♂️
What’s the difference between: stack<int>istack; And stack<int> vector<int>>istack; ? I’ve read that the second one is a container adapter but I’m not really getting the point if both can do the same thing.
ɛ n h ᴀ n c ɛ ґ 🧟‍♂️
I think it should be stack<int, vector<int>> istack; ?
Yeah sorry typo but i want to know how different it is from the first one
dearfl
stack is adapter use deque(default) as underlying container, so the first one use deque, the second one use vector
dearfl
Yeah sorry typo but i want to know how different it is from the first one
https://en.cppreference.com/w/cpp/container/stack you should read this
112
Hi guys how big is virtual studio ?@
Sandeep
Write a C function which takes 2 arguments size and alignment. The function should return a memory block of given size with given alignment. .......................this was an interview questions i was asked , can some one help me
Sandeep
Help with what?
#include <stdlib.h> #include <stdio.h> void* aligned_malloc(size_t required_bytes, size_t alignment) { void* p1; // original block void** p2; // aligned block int offset = alignment - 1 + sizeof(void*); if ((p1 = (void*)malloc(required_bytes + offset)) == NULL) { return NULL; } p2 = (void**)(((size_t)(p1) + offset) & ~(alignment - 1)); p2[-1] = p1; return p2; } void aligned_free(void *p) { free(((void**)p)[-1]); } void main (int argc, char *argv[]) { char **endptr; int *p = aligned_malloc (100, strtol(argv[1], endptr, 10)); printf ("%s: %p\n", argv[1], p); aligned_free (p); }..
klimi
this is the code for the implementation .. i tried to understand it but not clearly...
So you were at interview and now you are getting to know what your fault was?
Sandeep
So you were at interview and now you are getting to know what your fault was?
no.. i found that question in the interview expwerience for that company
klimi
im prepping for that company now
Alright, in this cas take the code, and try to read it line by line and you can write it as a comment to the code. Then you will have code with your notes and you will see what exactly you don't understand
● Igor
its about C++, i just wanted to question about golang because of C++ smart pointers hi, I was searching about Go and I am kind of curious because: Go is AOT compiled, and the compiler knows at compile time what will only be stack allocated and what will escape to the heap. but since the compiler can know that, why it needs a garbage collector? can't it add a reference counter at compile time, instead of using a garbage collector?
mj12
its about C++, i just wanted to question about golang because of C++ smart pointers hi, I was searching about Go and I am kind of curious because: Go is AOT compiled, and the compiler knows at compile time what will only be stack allocated and what will escape to the heap. but since the compiler can know that, why it needs a garbage collector? can't it add a reference counter at compile time, instead of using a garbage collector?
aside from the obvious problem with reference counting (that is circular data structures), tracking reference counts ahead of time isn't really possible as soon as the compiler can't prove which path(s) your code is going to take. besides that, could you elaborate on what exactly you mean by "can't it add a reference counter at compile time"?
● Igor
like func getSomething() *Something { return &Something{} } in C++ shared_ptr<Something> getSomething() { auto something = make_shared<Something>(); return something; } (i don't know if that actually works)
mj12
I meant like the compiler turning your variable onto a shared_ptr at compile time
> yeah but i believe circular dependencies generate memory leaks anyway there are strategies to deal with that > I meant like the compiler turning your variable onto a shared_ptr at compile time With that you really just have garbage collection, there isn't a whole lot that refcount based garbage collection implementations in other languages do much different.
mj12
but people say the garbage collector stops your code execution for freeing memory
The same thing technically happens as soon as the refcount of your shared_ptr reaches 0 (freeing memory isn't entirely free), also the reason why i was saying "refcount based garbage collection implementations".
Ludovic 'Archivist'
The same thing technically happens as soon as the refcount of your shared_ptr reaches 0 (freeing memory isn't entirely free), also the reason why i was saying "refcount based garbage collection implementations".
Well, not exactly Go, may "stop the world" to perform a garbage collection, this will halt all threads, do a parallel mark and sweep, before resuming execution. It will however detect any "loop" of derelict memory. shared_ptr will not be able to easily collect a loop of derelict memory (as every member of a cyclic graph may always have at least 1 edge pointed at them) but it will also not stop the world or affect execution of other threads significantly (edge cases may exist)
Ludovic 'Archivist'
If you are curious @igorcmelo I suggest you try to implement a tiny garbage collector in C to learn how these things work. It is easier than it seems to implement a mark-and-sweep for single threaded programs