typecast-operator

implementation of sizeof operator

时光总嘲笑我的痴心妄想 提交于 2019-11-27 18:23:18
I have tried implementing the sizeof operator.. I have done in this way.. #define my_sizeof(x) ((&x + 1) - &x) But it always ended up in giving the result as '1' for either of the data type.. I have then googled it for this.. and i found the code typecasted #define my_size(x) ((char *)(&x + 1) - (char *)&x) And the code is working if it is typecasted.. I dont understand why.. This code is also PADDING a STRUCTURE perfectly.. It is also working for #define my_sizeof(x) (unsigned int)(&x + 1) - (unsigned int)(&x) Can anyone please explain how is it working if typecasted and if not typecasted?

C++ floating point to integer type conversions

£可爱£侵袭症+ 提交于 2019-11-27 13:31:26
What are the different techniques used to convert float type of data to integer in C++? #include<iostream> using namespace std; struct database { int id,age; float salary; }; int main() { struct database employee; employee.id=1; employee.age=23; employee.salary=45678.90; /* How can i print this value as an integer (with out changing the salary data type in the declaration part) ? */ cout<<endl<<employee.id<<endl<<employee.age<<endl<<employee.salary<<endl; return 0; } thecoshman What you are looking for is 'type casting'. typecasting (putting the type you know you want in brackets) tells the

What does :: do in PostgreSQL? [duplicate]

不打扰是莪最后的温柔 提交于 2019-11-27 09:56:10
问题 This question already has answers here : Double colon (::) notation in SQL (4 answers) Closed 6 years ago . I have seen :: in variety of places involving postgres code I have seen on the net. For example: SELECT '{apple,cherry apple, avocado}'::text[]; It seems to be some sort of cast. What exactly is :: in postgres and when should it be used? I tried a bit of googling and searched the Postgres docs for :: but got no good results. I tried following searches in Google: postgres double colon

implementation of sizeof operator

落爺英雄遲暮 提交于 2019-11-26 19:24:49
问题 I have tried implementing the sizeof operator.. I have done in this way.. #define my_sizeof(x) ((&x + 1) - &x) But it always ended up in giving the result as '1' for either of the data type.. I have then googled it for this.. and i found the code typecasted #define my_size(x) ((char *)(&x + 1) - (char *)&x) And the code is working if it is typecasted.. I dont understand why.. This code is also PADDING a STRUCTURE perfectly.. It is also working for #define my_sizeof(x) (unsigned int)(&x + 1) -

C++ floating point to integer type conversions

别等时光非礼了梦想. 提交于 2019-11-26 16:22:31
问题 What are the different techniques used to convert float type of data to integer in C++? #include <iostream> using namespace std; struct database { int id, age; float salary; }; int main() { struct database employee; employee.id = 1; employee.age = 23; employee.salary = 45678.90; /* How can i print this value as an integer (with out changing the salary data type in the declaration part) ? */ cout << endl << employee.id << endl << employee. age << endl << employee.salary << endl; return 0; }