0
Sort, what's my mistake plz correct it
12 odpowiedzi
+ 6
PRIYANSHU GOYAL you need to call the function in separate line than use an for loop to iterate and read the sorted array and print that with the index values.
Below is the fixed code attached for your reference.
https://code.sololearn.com/cUh03PQkQ1re/?ref=app
+ 8
Vasiliy I just wrote that as general practice in sorting as sizeof is used most of the time for getting the length of array and string. I updated the code with sizeof concept and our discussion regarding size_t will help him to use those accordingly to the situation and usability ☺ ...
+ 7
Vasiliy size_t is used more often with STL. It always return an positive range unsigned value. When we are sure that some iteration index can't be negative in that case we can use this as it's return positive range only. Here we used this for array length or sizeof array and size of array always return an size_t type value so for general iteration of this we can use size_t in place of int type..
+ 6
Vasiliy yeah you are correct about size_t that it will takes the max memory of an object size but some thing that return the suze_t type we can use that. For an example Use size_t when dealing with the size/length of a memory object like sizeof() returns size_t type values,strlen() and length of array this all return an size_t. Here in sorting we use sizeof operator to get the elements length and size so we can use this size_t here. Both int and size_t has their pros and cons according to the place of using...
https://en.cppreference.com/w/cpp/types/size_t
+ 2
Martin Taylor, size_t is twice as large as int.
+ 1
GAWEN STEASY
What is this size_t, why not just write an int? 🤔
+ 1
GAWEN STEASY
This is exactly what I wanted to draw your attention to. If we didn’t know the size of the array, or it would change, then we would have to use sizeof in a loop instead of 5, and then perhaps it would be preferable for us to use size_t, (they are even consonant and themselves ask to work in pairs ☺️), but you Here you are comparing size_t with a very small int:
for(size_t i = 0; i < 5; i++)
+ 1
GAWEN STEASY, thanks for the answer, this is what I wanted to see, you need to start getting used to new data types ☺️
0
Thx bro
0
As far as I understand, size_t is used for a 64-bit system and in a 32-bit system it is useless, moreover, it takes up more cached memory than int and unsigned.