olli
I'm trying to get my way on LLVM currently.
> Actually, do you know of any compiler targeting arm7thumb (TDMI) with elf format? Then you shouldn't ask for "any" compiler :)
Anonymous
Everyone please this is urgent. I was working on an assignment and I realized that doing subtraction on unsigned integers work a bit strange. Please will anyone give me a quick tutorial on how unsigned integer subtraction works?
Anonymous
The subtraction is the same, just that your number cannot be negative, I'm not sure what confused you?
Yeah, realized that though numbers cannot be negative, I do get other positive numbers
Anonymous
Do you know why?
Anonymous
unsigned int gcd (unsigned int a, unsigned int b) { if (a == 0 && b == 0) b = 1; else if (b == 0) b = a; else if (a != 0) while (a != b) if (a < b) b -= a; else a -= b; return b; }
Anonymous
unsigned int gcd (unsigned int a, unsigned int b) { if (a == 0 && b == 0) b = 1; else if (b == 0) b = a; else if (a != 0) while (a != b) if (a < b) b -= a; else a -= b; return b; }
This code is meant to implement Euclidean algorithm to find the highest common divisor and using only unsigned integers, subtracting larger values from smaller values either result in a 1 or some other positive number.
Anonymous
I do not see why are you surprised about that, just use signed integers
Oh, my bad, kept my focus on the first instance of subtraction ignoring the else statement. Will look at the code more carefully
Anonymous
I do not see why are you surprised about that, just use signed integers
Just realized the while loop. Being working the whole day on my assignments that I am constantly missing out on small details in my assignment as I am very tired.
Anonymous
You helped a lot
Roxifλsz 🇱🇹
Anshul
How to use comparators with lower bound function in c++
Anonymous
Get some rest brah, otherwise you will just keep getting stuck like that
Will be sure to do that once I submit the assignments👍
Anshul
Let's say, I want a number which is just smaller than a given number or equals to given number, using comparators with lower bound function in c++
Anshul
For example Array a= 1,2,3,5,6 lower_bound(a,a+5,4,compare) So here the output should be 3
Anshul
How to write a compare function for this
Anonymous
How to write a compare function for this
Look the docs at cppreference.com
Anshul
I actually looked at this before but I don't understand much through this.
Anshul
Look the docs at cppreference.com
In this they're no where explaining passing own comparators
Anshul
Please anyone???
Anonymous
comp - binary predicate which returns ​true if the first argument is less than (i.e. is ordered before) the second. The signature of the predicate function should be equivalent to the following: bool pred(const Type1 &a, const Type2 &b); https://en.cppreference.com/w/cpp/algorithm/lower_bound
R
24. Which of the following statement shows the correct implementation ¢ of nested conditional operation by finding greatest and smallest number out of three numbers? (A) a>b?a>c?a:c:b>c?b:c; and a>b?a>c?a:c:c>b? b:c; (B) b>a?a>c?a:c:b>c?b:c; and c>a?a>b?a:c:b>c?b:c; (C) a>b?c>a? a:c:b>c?b:c; and b>a?c>a?a:c:c>b?b:c; (D) a>b?a>c?a:c:b>c?b:c; and b>a? c>a?a:c:b>c?b:c;
Brian
/warn not welcomed
.
/uwu
Soham
string s = "ccoooooding"; s[1] = '\0'; cout << s << endl; Output: coooooding why it's printing the whole string?? this trick works work char array why not for strings?
Soham
but it works here string s = "123\0bc"; cout << s; output: 123 here it is working
olli
but it works here string s = "123\0bc"; cout << s; output: 123 here it is working
yes, because you assign from a string literal, this is invoking constructor (5) Constructs the string with the contents initialized with a copy of the null-terminated character string pointed to by s. The length of the string is determined by the first null character. https://en.cppreference.com/w/cpp/string/basic_string/basic_string
Pavel
sorry, didn't get the point .. can u explain a bit more
std::string is a class it has its own operator<< definition, it resolves it differently than char*
olli
sorry, didn't get the point .. can u explain a bit more
if you initialize a std::string with a "string literal" the length of the string is basically determined by strlen. So std::string s = "123\0bc"; is the same as string s = "123";
Soham
std::string is a class it has its own operator<< definition, it resolves it differently than char*
yeah but why two different behaviour?? string s = "abcd"; s[1] = '\0'; cout << s << endl; here it is printing: acd and string s = "123\0bc"; cout << s; here it is printing 123
olli
yeah but why two different behaviour?? string s = "abcd"; s[1] = '\0'; cout << s << endl; here it is printing: acd and string s = "123\0bc"; cout << s; here it is printing 123
As stated above Constructs the string with the contents initialized with a copy of the null-terminated character string pointed to by s. The length of the string is determined by the first null character.
olli
ok got it.. Thanks ✌
std::string s = "123\0bc"; is basically the same as std::string s("123\0bc", strlen("123\0bc")); Which copies the number of chars (second argument) from the first argument. If you want to include the whole string you need to use std::string s("123\0bc", 6); ————- Just imagine for a second the behavior would be different.. how would std::string know when a string literal ends? Unless you specify the size it will only copy until the first \0 because it cannot know there might be a second one and probing for it might be undefined.
Earl B
I've been tearing it up in Solo Learn the last couple days. Really cool app! feels great to finally actually understand it enough to solve simple problems
Earl B
Just solved my first problem with zero errors on the first try
Gnostic Trades |
Do we have any group for competitive programming discussion?
Hariyana Grande
"C does not advocate to return the address of a local variable to outside of the function, so you would have to define the local variable as static variable."
Hariyana Grande
what does this stamemnt mean?
peppez
hello
peppez
who can help me with a program in c?
تاریکانون
How can I store full names e.g. Carl Peters... in an array using fgets in C
Amy
How can I store full names e.g. Carl Peters... in an array using fgets in C
You can declare and define a char array which length must longer than your name. Then call fgets function use you have known parameters.
Gnostic Trades |
Yes, but not this one.
Where? How can I join? I need to prepare for my interview, need a good group to get doubt cleared
Talula
Where? How can I join? I need to prepare for my interview, need a good group to get doubt cleared
I can't post a link for another group in this group, you can use search and you'll get the list...
Talula
Okay
Rakesh
#ide
Aditi s
I have exam in OOPs in c++, how to get started, what should I learn first
Aditi s
Oops- object oriented programming?
Anonymous
Oops- object oriented programming?
The interesting part is the 's'
Anonymous
Pavel
I have exam in OOPs in c++, how to get started, what should I learn first
Here, I googled this for you https://www.google.com/amp/s/www.geeksforgeeks.org/object-oriented-programming-in-cpp/amp/
Aditi s
Ok thanks
Dima
lol
Soham
how to ask question then??
Soham
what i used ubuntu paste as mentioned in the pin comment
Anonymous
how to ask question then??
From Pinned Rules Post -> About asking good questions: * [English](http://www.catb.org/esr/faqs/smart-questions.html) * [Translations](http://www.catb.org/esr/faqs/smart-questions.html#translations)
klimi
https://pastebin.com/wJq302Gd