/
is this the best way to get a pointer from a vector
/
what
/
why
klimi
you don't send your code formatted with `
klimi
so telegram thinks it's a link
/
auto *preset = &presets.at ( i );
/
is this the best way
pavel
Bro but this is c++ I asked in c
Your code not a c code too
Talula
#include <stdio.h> int main() { char seven='7'; printf(typeof(seven)); return 0; } Hello guys. How have you been. Here I am trying to print the type of variable. However I can't. What is wrong with the code? Can you help me. Thank you beforehand.
C doesn't support typeof as in C all variables are actually similar but they are assigned different sizes... they are simply memory locations. This is why C doesn't have string type (unless you use some kind of library).
pavel
It's useless to have typeof without templates
Sylvester Lim
Hi , is there any way for me to tell the system to put a [space] between the two strings when I combine them into another different array ? so i want it to output "I am strong" instead of "Iamstrong" string array[3]= {"I" ,"am", "strong" }; string name[1]; name[0]=array[0]+array[1]+array[2]; cout << name[0];
Sylvester Lim
because I am making a game with different stuff having different name lengths and attributes . eg: Honda City 8872 Fuel BMW 8271 Diesel Tesla Model X 2738 Electric The names and other attributes are being read and inserted into parallel arrays and instead of calling three parallel functions for name everytime i want to print the name, I combine them into one array called name[ ] ... do you get me?
Sylvester Lim
thank you
Talula
thank you
You're welcome
Dimka
hi guys) what is the best way to find array length in C?
Thadeu
@dimka_228 not search for it... keep the number of entries in a separate int variable. Why? Because there is no way to retrieve the length in a function that not declared the array. (the recipes you may find on web only work inside the function that declared the array)
Thadeu
sizeof(Arr)/sizeof(Arr[0])
👆only in the function it was declared. sizeof(arr) will return the pointer size if you do it in other function
/
Hi how i check what exceptions are thrown from a function
/
for example i want to know what are the exceptions thrown by mmap
/
or it doesnt throw exceptions
Anonymous
Can someone explain why unordered_map is so much faster than unordered_multiset when both of them seem to have the same internal working when doing something like a frequency count? Here's a little test I ran : cpp.sh/54rvp
习近平我肏你妈
mmap itself won't throw any. mmap is a function that can be used in C, so it can't throw any exceptions.
Dimka
are there general rules when should i use dynamic (malloc) or static(usual arrays) memory allocation? which is faster and why?
Dimka
im asking about pure C, not C++ with its new operator
Dm
are there general rules when should i use dynamic (malloc) or static(usual arrays) memory allocation? which is faster and why?
I think it's depends of lifetime limitation and size of arrays. When you allocate (with using any function) you send response to OS to allocate additional memory to your process and takes lots time. So I suppose that your can use static arrays when it's possible because of speed. This is just my opinion
Anonymous
hello everyone, advise game engines for c++ on a weak pc😁
pavel
Godot?
Batista
hello everyone, advise game engines for c++ on a weak pc😁
describe the type of processor of your pc in ghz and amount of memory? It would be easier for someone to help you knowing that.
Anonymous
it's possible to overload template class and simple class without having to define the same class again?
Anonymous
Hi how i check what exceptions are thrown from a function
You can't check what exceptions are thrown. Before C++11, the standard allowed you to specify the list of exceptions that can be thrown by a function. But this list is not validated by the compiler and this feature was also not useful as using it just led to severe unnecessary complications. So C++ deprecated this feature. However there is another related feature which allows us to specify that a function does not throw any exceptions. This is a useful feature as it allows optimizations by the compiler like not having to maintain the stack in an unwindable state. You can specify that a function does not throw any exceptions using throw{} (deprecated) or the noexcept specifier. To know whether a function does not throw any exception, you can use noexcept operator. It is a compile time operator. https://en.cppreference.com/w/cpp/language/noexcept
Anonymous
Can someone explain why unordered_map is so much faster than unordered_multiset when both of them seem to have the same internal working when doing something like a frequency count? Here's a little test I ran : cpp.sh/54rvp
How is the comparison valid? For it to be valid, you should compare an unordered_multimap to an unordered_multiset or an unordered_map to an unordered_set. But in your code snippet, you are comparing a map to a multiset. A multimap and a multiset have more overheads than a map or a set that don't allow multiple elements
Lucas
Can I check If a certain Key exists in a std::map in O(1)?
Lucas
Is checking If (map.count(key)>0) O(1)?
Tom
Visual studio has been a nightmare for me, it's always telling me that my code(C) isn't supported, having all the extensions installed, what might be the problem.
Tom
Sorry, visual studio code
Talula
Sorry, visual studio code
Which OS? Under Windows you have to install Mingw-w64...
Tom
Windows
Anonymous
Yeah right right I thought (from a rather misleading gfg article) that unordered_multiset stores the count of the elements present, when in reality it stores all the instances of the same element.
The GFG article is wrong. GFG is often wrong like many other Indian sites that teach programming. A map or a set stores elements (keys in the case of map) that support what is known as Weak (Partial) Order as opposed to Strong Ordering. So two elements A and B which don't appear to be the same can still be considered equal if neither is less than the other. In this case both elements must be stored in a multiset or a multimap. If the multiset were to store only the count and let us suppose say A is inserted before B, then if we search for B, then A is what will always be returned as opposed to the standard compliant implementations which can return B as well.
Buffer
https://pastebin.com/vwZX0ypR
Buffer
https://pastebin.com/vwZX0ypR
I think this is the more efficient code for matching any strings from database(an array) with or without case sensitivity and this will match any strings exactly what a user enters.
Buffer
//Program 33 //binary to Decimal convertor #include<iostream> #include<string> #include<cmath> using namespace std; int main() { string number; cout<<"Enter any binary number : "; cin>>number; int size=number.length(); int decimal=0; for(int i=size-1;i>=0;i--) decimal = decimal + number[i]*pow(2,size-1-i); cout<<"Decimal Value is : "<<decimal; return 0; }
Buffer
what is logical bug
Buffer
someone help me
Talula
someone help me
What do you want to do? I mean I don't even understand what you're planning to do with this code?
Buffer
Its a binary to decimal convertor
Buffer
Ohh got. It
Buffer
🙏
pavel
O(log(n))
Possible to check probability of key faster than this
Rajeev
for(int i = 0; i < n ; i++){ /*Do stuffs*/ } Error: expected ';' before '}' token } ^
Rajeev
Error in basic for loop.... I'm stucked... It never happened to me
Муртазо
look it happens
Rajeev
look it happens
Yes... inside the for loop. Thanks. How I missed it.🤦
Baki
#include<stdio.h> #include<conio.h> void fibonacci(int); void main(){ int k,n; int i=0,j=1,f; printf("Enter the range of the Fibonacci series: "); scanf("%d",&n); printf("Fibonacci Series: "); printf("%d %d ",0,1); fibonacci(n); getch(); } void fibonacci(int n) { static int first=0,second=1,sum; if(n>0){ sum = first + second; first = second; second = sum; printf("%ld ",sum); fibonacci(n-1); } }
Baki
My teacher told me that it is an iteration, is she correct? if yes then how?
ks
Hi i have a question regarding integer inputs, why is that when we assign a an integer X , but if we input characters like @@###$$%, then we cout and the result will get 0?
SKalinov
SKalinov
If function calls itself that is called a recursion
SKalinov
im just asking, in any case can this be iteration?
You can do it with iterations, for example: void fib(int num) {     int x = 0,y = 1, z = 0;     for (int i = 0; i < num; i++) {   cout << x << " ";       z = x + y;       x = y;       y = z;    } }