Anonymous
Tanks
Anonymous
Please i have somme dificult in the programmation of the SDL
Anonymous
somme one can help me ??
Anonymous
Which problem?
Parra
I dont want to see a video for understanding that
Parra
in fact, I don't understand how people can make a video of this
Parra
I never used videos to learn programming
Anonymous
Anonymous
A little text should be enough
Parra
😅👍
Parra
thanks for understanding
S.
Same. Prefer to read text. Simple and direct.
Aspire
Oky sorry
Mat
Oky sorry
No problem👍
Aspire
Actually i m trying to make this programe
Aspire
But i dnt knw where i m wrong
Aspire
Ok
Aspire
int SquareArea(double width) { return width * width;
Aspire
is this right ??
Aspire
i think int is incorrect declared
Aspire
i mean type mismatch
Varun
#cbook
Aspire
m i right ??
Mat
i mean type mismatch
But you can cast a double to int
Mat
It will floor the number
olli
i mean type mismatch
well there are several rules that allow compilers to convert the floating point value into an integral one. The reult ist truncated, UB if the truncated value cannot be represented as destination (int) type [conv][conv.fpint] apply
Aspire
thanku
VJ
#include<stdio.h> void fun(int *p) { static int q = 10; p = &q; } int main() { int r = 20; int *p = &r; fun(p); printf("%d", *p); return 0; }
Pavel
why does value of p is not changing??
Because setting pointer in fun makes no sense. You need to set value *p = q;
olli
how??
e.g. *p = q;
S.
in fun
olli
why does value of p is not changing??
the pointer p in fun and p in main are not the same. They may point to the same location though
olli
both are pointing out the same location am i right??
yes, before p = &q; they point to the same location.
olli
if you want to change what the pointer points to and see it outside the function you need to pass a pointer to pointer to the function
VJ
if you want to change what the pointer points to and see it outside the function you need to pass a pointer to pointer to the function
ohh if u need to change pointer value it need to be carry by another pointer to pointer now am i right???
Pavel
Because if you just want to have that 10 outside, you don't need a pointer to pointer
S.
Actually you can consider this in a simple way: you can do *(address) = some value; to modify the value at that address, what you need to think about is just the type of the "address"
S.
For int *p = &r; fun(p); , you just copy the address stored in p, and pass it to fun
S.
For int *p = &r; fun(&p);, you just copy "the address of p" and pass it to fun
S.
And then in fun, you do the *(address) thing
VJ
so i just cpy the address in the above program
olli
yes, your code does copy the pointer
S.
Yes, in C, if not optimized by the compiler, you can say there's only one way: pass by value, and for the pointer case, it passes the "value of address"
S.
All are done by copy
VJ
thanks man
S.
no problem
VJ
#include "stdio.h" int main() { char a[] = { 'A', 'B', 'C', 'D' }; char* ppp = &a[0]; *ppp++; printf("%c %c ", *++ppp, —*ppp); } Output : C A
VJ
i didn't understand how the output is c a
VJ
??
olli
undefined behavior
olli
Output C A is not guaranteed
olli
iirc clang yields a different result
Anonymous
Yes
S.
Not even #include <stdio.h>
Anonymous
iirc clang yields a different result
clang would be C B if I see it correctly
Anonymous
Any recommendations on how to start learning STL Lib except geekforgeeks?
VJ
Output C A is not guaranteed
in my compiler i get o/p as C A
olli
in my compiler i get o/p as C A
yes, gcc produces C A. The parameters passed to printf have side effects. Since neither C nor C++ define the evulation order of function parameters this is UB. Hence the compiler can do output whatever it wants
VJ
SO ITS DEPENDS ON COMPILER
olli
yes
VJ
hence it is ub
VJ
okay
olli
don't write code that triggers UB in the first place :)
VJ
okay
Anonymous
Search for sequencing rules on google
S.
But
S.
https://stackoverflow.com/a/46171943/824501
S.
C++17 did some unpleasant modification
olli
this does not affect function parameters
S.
it doesn't. just remind me things changed a little.
S.
and i don't understand why the standard allowed this
S.
it brings confusion anyway