'''''''
🙂good luck
klimi
Then you can't really use recursion too
klimi
So you will have to use so loop where you will loop though it, and do it correctly
klimi
That means probably the tmp+10 is not correct
klimi
I dont have it
klimi
I would have to code it, just like you
klimi
Weird, is that assignment or something?
.
Google for global variables
Yeah but isn’t it a bad practice to use global variables for a single function?
Anonymous
How do I declare variables out of the function and then use them inside? Is it possible to use variables from another function?
> Is it possible to use variables from another function? using appropriate pointers and references (as long as the variable exists in the stack, e.g. calling another function from a function with pointers to local variables as arguments)
Anonymous
Yeah but isn’t it a bad practice to use global variables for a single function?
everything is bad practice if you use it wrong. if your use case requires global variables and there is no alternative way, obviously global variables cannot be bad practice.
+
Hi guys I'm recently working on a c++/qt project For that I need to subclass Qprogressbar class and make some changes on it, everything is ok, but I need something else that I don't know how can I make it, I want to show a shadow only on bar of progress bar (not the whole progress bar, just bar) but I don't have any idea that how can I do it... Anyone can help?
#
https://pastebin.com/sNpae1q1 what mean "marbles + SIZE?"
Anshul
vector<vector<string>> rank(100,vector<string>(n,"")); for(int i=0;i<n;i++) { rank[a[i].marks].push_back(a[i].name); } for(int i=100;i>=0;i--) { for(int j=0;j<rank[i].size();j++) { cout<<rank[i][j]<<endl; } }
Anshul
this is not giving any output, where i'm going wrong in it
SR27
int l=0,h=0; while(h<n) { if(a[h]==0) { int temp=a[h]; a[h]=a[l]; a[l]=temp; l++; h=l; } h++; } time complexity is less than O(n) ? but i am getting time limit exceed why ?
Ausir
Hi guys, I decided to learn C++, all good tips and links for free books are appreciated! Can you give me a starting point for the syntax? My knowledge base in programming is built by C and Java programming, I know a little bit of Python also.
Anshul
in this question i want to build a function that sorts students according to their marks. i made a Student class. in that i made two variables, marks and name. now my idea is that i'll take input marks and names and add them into a student array. and later iterate on this array of students and go to the marks index and push_back that student name into my vector<vector<string>>
Anshul
vector<student> v[101] is this an array of vector or it is a vector having num of elements=101 elements
Anshul
anyone please?????
Ausir
Why do you want to learn C++, any specific reason or you want to learn it for fun?
I want to have it in my "inventory" ahahah i'm also interested in understanding game dev with unity and making windows app with gui (I know how to make it in java but why not with C++ also?)
Ausir
For learning it is fine...
Yea can you help me? Some manual?
adult breastfeeding
Yea can you help me? Some manual?
courses from udemy are useful
Talula
C++ has probably very high number of manual on Internet, just google it.
Ausir
If you interested in unity and window apps try c#
That's the following argument of my thing to learn list
Anonymous
vector<vector<string>> rank(100,vector<string>(n,"")); for(int i=0;i<n;i++) { rank[a[i].marks].push_back(a[i].name); } for(int i=100;i>=0;i--) { for(int j=0;j<rank[i].size();j++) { cout<<rank[i][j]<<endl; } }
This is because when you construct the vector of vectors, you are initializing each inner vector to n empty strings already. So this is what you are probably printing out. You could initialize rank instead as follows: vector<vector<string>> rank(101, vector<string>{}); or simply as vector<vector<string>> rank(101);
slaughter
## Rules #pinned * You are not entitled to an answer, getting angry about not answered questions will get you warned. * Not checking your problem in google (or any other search engine) first will get you a warn. * Asking to solve an assignment/test/whatever without trying it first yourself will get you a warn or will get you BANNED. We won’t write a code for you, but we can push you forward and suggest something. * Before posting a long code snippet think twice and read the Resources section below. * No “best book” or “best youtube channel” requests, use /get cbook and /get cppbookguide chat commands. * No “best ide” requests, use /get ide chat command to see the suggestions. * Asking for something that is in the pinned message right after joining WILL GET YOU BANNED. * C/C++ discussion preffered (assembly also allowed), asking about other languages (or groups for other languages) right after joining will get you BANNED. * Reverse enginnering, hacking and related topics are allowed, but asking to hack facebook, instagram, etc. is NOT allowed. Also if you ask "how to become a hacker" and obviously have zero knowledge on anything related to that you may get warned or banned. * Legitimate requests for help on code and programming questions are welcome. A request is considered legitimate if it describes your problem, what you've done so far and what went wrong. Requests such as "write my program" or "do my homework" are never considered legitimate. Asking not legitimate questions will result in a warn or ban. See https://stackoverflow.com/help/mcve on how to write good questions. * Asking for book recommendations is ok, but "pls give pdf book" is not allowed, find books by yourself. Posting illegally copied books (or links to those books) is also not allowed and will get you BANNED. * Only English language is allowed, if you speak shitty English or don't understand anything in English YOU WILL BE BANNED. * A little bit of programming related memes, jokes, shitposting are allowed. * NSFW content (porn, nudity, etc.) is not allowed. * Spamming/advertising (job posts are also ads, so ask an admin before posting) will grant you a warning or an immediate ban if you do it right after joining. * Religion, politics and ideological topics are forbidden. * Long code snippets must be posted via a snippet website(links below), posting pictures of code and posting long snippets in the group is not allowed. * If you encounter a problem, while using dev C++ or turbo C/C++, you will not be helped, use another more modern IDE. * Don't post compiled executables, that is obviously a security risk. * Personal messages without asking beforehand are not allowed. * If you want to post a link or some article in this chat you will need an admin approval first ## Resources C/C++ group India: http://t.me/c_cpp_india 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) For posting long code snippets: * [GitHub Gist](https://gist.github.com) * [Ubuntu Paste](https://paste.ubuntu.com/) * [Pastebin](https://pastebin.com) ## Reports If you notice any forbidden content, please use the /report command while responding to the offending post to report it to the admins.
Is it a channel or a military regime 😂
Dima
Lmao
Anonymous
When we can run the code int & char interchangeable at almost time like; Int variable = 'b'; then what is the need to mention 'int' for whole integers and 'char' for characters in C ?
Anonymous
When we can run the code int & char interchangeable at almost time like; Int variable = 'b'; then what is the need to mention 'int' for whole integers and 'char' for characters in C ?
When variable is defined as int variable = 'b'; what do you think will be the output when you print variable? A char is supposed to be big enough to hold the basic character set of the machine. It is meant to be used for representing characters and not for arithmetic operations except in special cases. On most machines a char is 8 bits long and on such machines if you need an 8 bit integer, you should use int8_t.
Amy
If we put %c format specifiers then it will print as 'b' itself right ?
Int type size is bigger then char, so if conversion from int to char, you must ensure the int's variate is in the range of char type can express.
Amy
than
Anonymous
Int type size is bigger then char, so if conversion from int to char, you must ensure the int's variate is in the range of char type can express.
Thanks, I just used for the simple programming to check isalpha, isupper, isdigit functions and it's worked fine for that.
Anonymous
#include<stdio.h> #include<stdlib.h> #include<ctype.h> #include<string.h> #include<math.h> int main() { int something = 'k'; if(isalpha(something)) { printf("%c a alphabhet\n", something); if(isupper(word)) { printf("%c is a capital letter\n",something ); } else { printf("%c is a small letter\n",something); } } else { if(isdigit(word)) { printf("%c a digit\n",something ); } else { printf("%c is a special character",something ); } } return 0; }
..
Jumpstart? anyone writting?
Nils
using namespace client; auto projectListElem = document.getElementById("project_list"); projectListElem->set_innerHTML("<tr><th>There are no projects (yet). Create one to continue!</th></tr>"); Any idea why it crashes at the set_innerHTML(...)?
Anonymous
It doesn't even print null strings. Also vector<vector<string>> rank(101, vector<string>{}); This means it have 101 elements in it and each element is an vector of string which have null elements??
Yes that is the point because you are calling push_back on them. So they should be empty to begin with. And the reason why I suggested 101 elements is because you were accessing the vector at index 100. If a vector had only 100 elements, this would be undefined behavior.
Anonymous
If we put %c format specifiers then it will print as 'b' itself right ?
No. The output depends on the size of int and also the architecture like little endian or bigendian. And my point was that char is used to store characters and int is used for integers (mostly to do arithmetic with them). Just because you can do arithmetic with chars, you shouldnt unless you have a valid reason to do so.
Anonymous
Hello everyone
SR27
vector<int> kLargest(int a[], int n, int k) { sort(a,a+n); vector<int> ans; for(int i=n-1,j=0; i>n-k; i--,j++) ans[j]=a[i]; return ans; }
SR27
what is the error in it?
Anshul
Bro i guess this question can be optimally done by max heap
Anshul
So try that out with O(n) time
Anonymous
? they are not returning a memory location
Anshul
Okok
Anonymous
that's not how objects work :/
SR27
you need to allocate memory. use ans.emplace_back(a[i])
with vector i cant do ans[j]=a[i]; this ?
Anonymous
with vector i cant do ans[j]=a[i]; this ?
no. ans[j] doesn't exist
SR27
ok
Ludovic 'Archivist'
vector<int> kLargest(int a[], int n, int k) { sort(a,a+n); vector<int> ans; for(int i=n-1,j=0; i>n-k; i--,j++) ans[j]=a[i]; return ans; }
You need to resize your vector before trying to index into uninitialized/non-existing memory. Use the resize function before doing your assignments. Also, it may be wiser to just use push_back than an assignment
SR27
what this ans.emplace_back(a[i]); does?
Anshul
that's not how objects work :/
Thank you, I got it now
Anonymous
vector<int> kLargest(int a[], int n, int k) { sort(a,a+n); vector<int> ans; for(int i=n-1,j=0; i>n-k; i--,j++) ans[j]=a[i]; return ans; }
oh right. you can do vector<int> ans(k); OR vector<int> ans; ans.resize(k); followed by the assignment operator you are using already. OR vector<int> ans; ans.reserve(k); (optional, but efficient since push_back()/emplace_back() will do multiple allocations if not reserved) followed by calls to push_back() or emplace_back()
Anonymous
what this ans.emplace_back(a[i]); does?
For integers, it is pretty much like push_back. Not much of a difference
Anonymous
Bro i guess this question can be optimally done by max heap
this is the actual answer though SR27 if you are doing this for competitive programming
Anonymous
but i dont know about it
Learn about it. C++ has algorithms library that does this for you
Anshul
When you return an object from a function, does it return the address of that object?
Ludovic 'Archivist'
reserve() + push_back(), not resize() + push_back()
resize or push_back is what I meant