/
is this the best way to get a pointer from a vector
/
what
Dm
/
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
Talula
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];
Talula
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?
pavel
Sylvester Lim
Sylvester Lim
thank you
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)
Anonymous
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
pavel
Anonymous
hello everyone, advise game engines for c++ on a weak pc😁
pavel
Godot?
Anonymous
it's possible to overload template class and simple class without having to define the same class again?
Anonymous
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
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)?
mj12
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.
Talula
Tom
Sorry, visual studio code
Tom
Windows
Муртазо
Anonymous
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
Buffer
what is logical bug
Buffer
someone help me
Anonymous
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
Talula
Anonymous
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
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
Baki
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);
} }
im just asking, in any case can this be iteration?
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;  
 }
}
Baki