Anonymous
See what happens
V01D
V01D
Lemme guess, you get a negative number
V01D
Or buffer overflow
V01D
probably buffer overflow
Anonymous
Anonymous
It is undefined what happens
V01D
Don't values wrap around to its lowest value
V01D
Mar!o
Just make it an unsigned an it's no longer undefined behaviour.
Pavel
V01D
V01D
So it was right?
V01D
Pavel
V01D
Oh.
I thought it wasn't.
Guess I got signed and unsigned mixed up
V01D
What if a signed int is needed?
Isn't this a fundamental flaw?
Harsh
Anonymous
Anonymous
Reverse the string
Anonymous
Then compare both strings
Mar!o
It is indeed a misdesign in the C/C++ standart in my opinion!
The compiler can use UB to optimize, but I don't care.
I mean we have C++20 and signed overflow is still UB - that's one of the reasons I use Rust...
Harsh
Then compare both strings
You can do:
scan str
rev_str = strrev(str)
if(strcmpi(str, rev_str)==0)
> palindrome
Else
>Not
V01D
Mar!o
When I use Assembly I'm very carefully but if I write in a high-level language I want to be save from that shit...
Don't get my wrong I love C and C++ but some designs are just stupid in my opinion...
V01D
Cristian
Anyone knows how to do this with c graphics?
V01D
Is there a book or a video that teaches how to writer SAFE code?
V01D
V01D
Mar!o
Probably, I don't have any but I think there is a book called "Safer C" or something like that.
My original idea was to build my language and VM in C but there are just better options like Rust.
Today I use Rust and Assembly in combination with some C sometimes.
Rust might not have a real ISO standard yet, but without the "unsafe" keyword there is almost no way to invoke UB.
Mar!o
Imagine having a car or plane crash because of UB in a VM!
V01D
V01D
Well , I am a game dev.
Unreal engine, I have to use C++, so...
Mar!o
No thanks 😅
That's why there are special versions of C for cars or rockets but C is old and sometimes we should move on to newer tools.
Harsh
Konstantin
Mar!o
These are basically strict guidelines.
V01D
Mohit ^_^
Let's say I have 2 vectors of char, say a and b, and I want to link one to another. I created an array of pointers, but after I use std::sort on 'a', the pointer address is changed to sorted order of a. I still want to keep the old reference somehow but can't figure out how. Any suggestions ?
Mohit ^_^
Thanks. Actually I want to bind a to b such that I can go from b to a directly, without traversing and searching the entire sorted list, a.
a & b are identical initially but I've sorted a later.
Mohit ^_^
Got it. Tysm Madhu
Vlad
Vlad
From allocating singular ints on the heap, to using new and delete in the first place
Dima
I use Arch, btw
Dima
King Phyte 🐍
Andrew
Anonymous
Anonymous
Vlad
2d array is an array of arrays
Vlad
Think of it as it's a T**
Vlad
You derefence it twice
Vlad
By the first and second subscript accordingly
Vlad
Yes
Vlad
But we move inside the row
Vlad
Nvm you move along the row
Vlad
Not the column
Vlad
It is
Vlad
cuz second subscript selects a column
Vlad
int arr[height][width];
for(int i = 0; i < height; ++i) {
for(int j = 0; j < width; ++j) {
printf("%d ", arr[i][j]);
}
printf("\n");
}
Stare at this piece of code until you get it
INDIA
What help you want exactly?
#include<iostream>
using namespace std;
class Employee;
class clerk {
public:
void print(Employee);
};
class Employee
{
string name,gender,dep;
int empid,age,sal;
public:
friend void clerk::print(Employee);
void read()
{
cout<<"\n enter name ";
cin>>name;
cout<<"\n enter empid ";
cin>> empid;
cout<<"\n enter age";
cin>>age;
cout<<"\n enter gender ";
cin>>gender;
cout<<"\n enter salary ";
cin>>sal;
cout<<"\n enter department";
cin>>dep;
}
void show()
{
cout<<"\n the information of employee is:";
cout<<"\n name "<<name;
cout<<"\n empid "<<empid;
cout<<"\n age"<<age;
cout<<"\n gender"<<gender;
cout<<"\n salary"<<sal;
cout<<"\n department"<<dep;
}
Employee()
{
cout<< "\n default constructer called";
}
~Employee()
{
cout<<"\n destructor called";
}
};
void clerk::print(Employee emp)
{
cout<<"\n name "<<emp.name;
cout<<"\n age "<<emp.age;
cout<<"\n gender "<<emp.gender;
cout<<"\n salary "<<emp.sal;
cout<<"\n department "<<emp.dep;
}
int main()
{
Employee emp;
emp.read();
clerk cl;
cl.print(emp);
}
INDIA
What help you want exactly?
#include<iostream>
using namespace std;
class Employee;
class clerk {
public:
void print(Employee);
};
class Employee
{
string name,gender,dep;
int empid,age,sal;
public:
friend void clerk::print(Employee);
void read()
{
cout<<"\n enter name ";
cin>>name;
cout<<"\n enter empid ";
cin>> empid;
cout<<"\n enter age";
cin>>age;
cout<<"\n enter gender ";
cin>>gender;
cout<<"\n enter salary ";
cin>>sal;
cout<<"\n enter department";
cin>>dep;
}
void show()
{
cout<<"\n the information of employee is:";
cout<<"\n name "<<name;
cout<<"\n empid "<<empid;
cout<<"\n age"<<age;
cout<<"\n gender"<<gender;
cout<<"\n salary"<<sal;
cout<<"\n department"<<dep;
}
Employee()
{
cout<< "\n default constructer called";
}
~Employee()
{
cout<<"\n destructor called";
}
};
void clerk::print(Employee emp)
{
cout<<"\n name "<<emp.name;
cout<<"\n age "<<emp.age;
cout<<"\n gender "<<emp.gender;
cout<<"\n salary "<<emp.sal;
cout<<"\n department "<<emp.dep;
}
int main()
{
Employee emp;
emp.read();
clerk cl;
cl.print(emp);
}
Harsh
Huh;_;
INDIA
Sir I am not able to understand how friend function can take empid and display all other information
INDIA
Huh;_;
Sir how this question can be done using arrays
INDIA
Huh;_;
Thanku sir for responding to my message🙏🙏
INDIA
Anonymous
Write a program in c++ that fined the area of a cub
Anonymous
Please any one help me ow
Valentine
Hi! Why does this thing behaves like this?
Valentine