Anonymous
If you're unable to think, leave programming, it's not for you
Aman
bro i was thinking from yesterday
Anonymous
Lmao
Anonymous
or go for js and python, lol
No, they need to think either Sometimes even harder because of dynamic types
Aman
the question for which i had written the code is that i had to print first non repeating character in a string so for that i had used unordered map to count the frequency of character and for the second loop for which u all had pointed out the error i am checking the frequency of character whether it is equal to 1 or not if it is 1 then it will return the first non repeating charcter from there only
Bipin
For this set of code output i am getting is 0...pls guide me
Aman
For this set of code output i am getting is 0...pls guide me
you need to use5.0/9.0 instead of 5/9 in cel variable
Aman
as it is a float variable
Bipin
Thank you 😊
Anmol
Just use brain ffs
Jøhn
Don't write C if you are this dumb, the world has enough memory bugs already
Vlad
Why shouldn't it be?
Vlad
Scanf just treats pointer as integer
Vlad
It doesn't mean that you can access data by that address
Vlad
Implicit conversion from an integer
Vlad
If you were to have warnings enabled you knew
Vlad
*c accesses data
Vlad
Which does not belong to you
Vlad
It's user input after all
Vlad
Have a read about pointers and such
Vlad
Yes. You can output an address, but not the data by that address.
Vlad
Hence it is not an address of a variable created by you
Vlad
It is what is called undefined behavior.
Vlad
Anything could happen really :P
da
Segment error is an exception on linux
Vlad
No accessing data via invalid address
Vlad
*((int*)(0x0)) += 2; // will fail almost everywhere
Vlad
It does not lead to your data. Do you understand?
Nameful
it happens when you try to make an invalid memory operation
Vlad
Also why don't you use "%p" for scanf?
Vlad
int and pointer are different in size
Nameful
why would what work?
Vlad
so what
Vlad
scanf writes into a region of 4 bytes
Vlad
Instead of 8
da
It may also work on Linux. It's not certain
da
😂
Vlad
%d and %x expects int, which is 4 bytes
V01D
If you need a compiler to know if your syntax is correct, you need to read another book or two.
Anonymous
C is not a safe language. safety is your responsibility.
Anonymous
the *c is undefined behaviour based on whether it points to valid data or not. code that exhibits undefined behaviour is ill-formed.
Anonymous
:/ you don't consider whether it is pointing to anything or not. a program that exhibits undefined behaviour does not need a reason for working good/bad.
Anonymous
idk much details about this. googling - https://stackoverflow.com/questions/22180312/difference-between-undefined-behavior-and-ill-formed-no-diagnostic-message-requ
Anonymous
the question itself was very well written. i just finished reading
V01D
Undefined behaviour can also mean your code runs just fine - it doesn't always mean something unexpected happens
V01D
It seems to work fine on your machine, but not on another - both are due to undefined behaviour.
V01D
Rip
Vlad
C standard
Vlad
google "c standard draft"
Vlad
Yes only drafts, but that's all you need
Anonymous
Hye
Anmol
int main() { int x = 5; int y = x++ * ++x; cout << y << '\n'; }
Anmol
is this like undefined behaviour?
Pavel
is this like undefined behaviour?
if I recall correctly, it is in C++ prior C++17
su
is this like undefined behaviour?
what are you talking about?
Anonymous
if I recall correctly, it is in C++ prior C++17
it should still be undefined behaviour. value computation of x++ and ++x happens before value computation of *. value computation of x++ is sequenced before its side effect. side effect of ++x is sequenced before its value computation.
Anonymous
not enough info to form a well defined sequence @Anmol3299
Anonymous
the result will be different based on whether x++ or ++x's value was computed first. additionally, if x++ was computed first then the result will depend on whether x++'s side effect was completed before ++x's side effect calculation.
Pavel
Oh I see
Pavel
Interesting case
Anmol
I actually tried this on compiler explorer on various compilers, it was only icc (intel compiler) which actually gave 36. All other gave 35 as answer
su
it is undefined behaviour
operation precedense not defines order of arguments to be processed? or compiler option does not affect actual values?
Anonymous
I actually tried this on compiler explorer on various compilers, it was only icc (intel compiler) which actually gave 36. All other gave 35 as answer
undefined behaviour -> ill-formed program -> no need to determine why the result is good/bad 🤷
Anonymous
operation precedense not defines order of arguments to be processed? or compiler option does not affect actual values?
no. order of evaluation is defined by sequence point rules (C) and sequenced before rules (C++). precedence and associativity is used to group operands with operators.
su
undefined behaviour -> ill-formed program -> no need to determine why the result is good/bad 🤷
i think you are totally wrong, cause such a silly example can be found in 1984, or you think you are the only smart person in the universe?
Anmol
undefined behaviour -> ill-formed program -> no need to determine why the result is good/bad 🤷
I was just trying to check how various other compilers try to do this lol