Daulet
/
/
/
/
/
/
Anonymous
Pavel
How using reference is safer than pointer as a question?
1. Inside a function if you receive a reference, you know for sure it's not null, so you can't do nullptr dereference
2. You can't accidentally change address instead of value
3. You can't accidentally be passing const pointer to a mutable value instead of pointer to a const value
Pavel
Technically you can dereference a nullptr into a reference of course, but it's UB from that moment already, so no need to think about that inside the function
DaviChan
anyone here has used clang-query? I'm trying to define a matcher for const reference parameters. 🤔
DaviChan
and isConstQualified does not work since the reference is not directly const, but the const only applies to the value the reference is refering to
Unknown man
Jahongir
what does ?(question mark) operator do in c++
Daulet
Anonymous
DaviChan
<condition>?<true>:<false>
DaviChan
if condituon is true, it will evaluate to <true>. Otherwise to <false>
DaviChan
example:
int a = 2>3?4:5;
DaviChan
a will be set to 5
Anonymous
Amazing now I understand bro
Jahongir
thank you all so much
DaviChan
nice🔥
DaviChan
Sure, no worries. I'm thinking about making a playlist on youtube about C++. Would anyone here watch it? 🤔
Jahongir
ys
Anonymous
I'm a beginner in c programming somebody help me out to understand the basics so that I can apply in c++
DaviChan
Nice 🔥. I will think about what to cover and will link the playlist here once I uploaded the first video :3
DaviChan
Anonymous
Anonymous
DaviChan
😅
DaviChan
im like on the job 12h a day when i include traveling time. Kinda bad
Daulet
Who want to get C++ challenge
Dima
lol nice try to give out your assignment
DaviChan
Just ask ^^. Might have time later
DaviChan
Like templates or old school preprocessor stuff?
Daulet
Daulet
Anonymous
Anonymous
Anonymous
DaviChan
No, templates
So its really C? Just using a C++ compiler to compile :p 😂
DaviChan
DaviChan
Sorry, im not 100% sure if i got the task
Daulet
One exception. Dimension not bigger than 3
DaviChan
DaviChan
Daulet
DaviChan
If yes, its pretty straight forward.
but it got me thinking how I would do it without
DaviChan
Well ofc. you can always just static_assert(T < 4)
Daulet
DaviChan
Okay 🤔
DaviChan
can't you just:
<std::integral T, typename Q>
class template_array final {
Q* values;
public:
template_array():
values{ malloc(sizeof(Q)*T)}{}
~template_array(){
free(values);
}
};
DaviChan
ofc. define some geters and seters
DaviChan
Also not good. since it always heap allocates.
DaviChan
but its simple
Daulet
DaviChan
Just a template parameter
Александр
Hello! Why do I have this message?
-narrowing conversion of ... from 'int' to 'float'.
Is it because I store values in {} braces?
DaviChan
No, you need to write the value as a float literal: 1.0f for example
DaviChan
initializer lists dont allow implicit convertions
Александр
So how do I write it in here? And furthermore, why isnt there the same warning in the tutorial? I have done everything the same.
LinkRunData{0, 0, LinkRun.width/12, LinkRun.height}
DaviChan
Not sure what it expects, but 0 is an integer literal, so ypu would need to write 0.0f instead
DaviChan
Hope that fixed it. Need to go :) good night folks ✌
Deepak Chaurasia
#include <stdio.h>
int factorial(int i);
int main() {
int f;
printf("Program to do factors of a no.\n");
printf("Enter a no.");
scanf("%d" ,&f);
// Write C code here
printf("the factorial of %d is %d", f ,factorial(f));
return 0;
}
int factorial(int i){
if (i ==1 || i==0){
return 1;
}
else{
return i* factorial(i-1);
}
}
Deepak Chaurasia
Giving null or wrong output,any problem in code?