0
Compare of two different Data type
I want know that can we compare the data type of variables in an expression. If possible how?
9 odpowiedzi
+ 5
unknown
Have you figured it out?
So I tried finding that question (I slightly remember being similar), but I can't find it anymore, I didn't bookmark the thread either unfortunately.
But I found some links, might be helpful, there is the easy way and there's also the bit more complex way, but since you wanted this, it shouldn't be a problem.
[Easy way]
http://www.cplusplus.com/reference/typeinfo/
[Not so easy way]
https://stackoverflow.com/questions/19773453/ask-a-variable-what-data-type-it-is-in-c
https://stackoverflow.com/questions/81870/is-it-possible-to-print-a-variables-type-in-standard-c
I still don't understand why you want to check variable type though, since C++ is statically typed language - you know already what type something is as you declare it in code.
+ 3
Then you shouldn't have that many languages specification in Relevant Tags unknown .
+ 2
if (typeof a == typeof b)
+ 2
Ok Ipang . Do you have the answer for this?
+ 2
unknown
What exactly did you mean by comparing data type in expression? you want to check if the variables' type are all the same or what?
I remember slightly a question asking how to check for a variable's type, but that is not comparing the data type. Elaborate some more on this thought will you?
+ 2
Yes i want to check the data type of the two variables, weather they are same or not? Ipang
+ 2
Thank you Ipang
+ 2
You're welcome, anyways, will you share with me what is it you're trying to code? I'm curious, maybe share that code you're currently working on unknown
0
I want in c++