There are two AND operators in C, logical AND (&&) and bitwise AND (&).
The return type for logical AND is always bool, however logical AND only works when both operands can be implicitly cast to bool. The value 0 is always regarded as being false while all non-zero values are regarded as being true.
The return type for bitwise AND is that of the largest of its two operands. For instance, the return type of int & char is int (same as the l-value) while the return type of char & int is also int (same as the r-value).
Wiki User
∙ 8y agoNo. There is no default return type for functions, it must be explicitly specified in both the function declaration and in the definition. To specify no return value, return void. To return a variant type, return void* (pointer to void). Otherwise return the exact type.
A ternary operator is an operator that requires three operands, as opposed to a binary operator that requires two operands and a unary operator that requires just one operand. C++ has just one ternary operator, the conditional ternary operator: <boolean expression> ? <expression #1> : <expression #2>; If the boolean expression evaluates true, the first expression is evaluated, otherwise the second expression is evaluated. A typical usage of this operator is to return the larger (or smaller) of two values of type T: template<typename T> T max (T a, T b) {return a<b ? b : a}; template<typename T> T min (T a, T b) {return a<b ? a : b}; These are really nothing more than notational shorthand for the following: template<typename T> T max (T a, T b) {if (a<b) return b; else return a; }; template<typename T> T min (T a, T b) {if (a<b) return a; else return b;}; However, because ternary expressions are evaluated, the return value of the expression can be used in more complex expressions: int a=42, b=0; // ... int c = ((a>b ? a : b) = 1); In the above expression, whichever is the larger of a and b will be assigned the value 1 which will also be assigned to c. Thus a and c become 1 while b remains 0.
class foo { private: int m_data; public: foo (int data=0): m_data (data) {} foo (const foo& source): m_data (source.m_data) {} foo (foo& source): m_data (std::move (source.m_data)) {} // operator overloads: assign foo& operator= (const int source) { m_data = source; return *this; } foo& operator= (const foo& source) { m_data = source.m_data; return *this; } foo& operator= (foo& source) { m_data = std::move (source.m_data); return this; } // compound operator overloads: increment and assign foo& operator+= (const foo& rhs) { m_data += rhs.m_data; return *this; } foo& operator+= (const int rhs) { m_data += rhs; return *this; } };
Because int is the most common data-type in C. Don't rely on this though, always specify the return type explicitly.
Well, it depends on what you mean by the type of a function. There are user defined functions and library functions.
In C, the sizeof operator can be considered a dummy operator because it does not perform any operations on the data but simply returns the size in bytes of a variable or a data type.
Yes, it is possible to do this. Consider the following example that returns an instance of class C from the sum of two instances of class A. #include <iostream> class A { public: A(int i=0):m_data(i){} int m_data; }; class C { public: C(int i=0):m_data(i){} int m_data; }; C operator+(const A&a,const A&b) { return(C(a.m_data+b.m_data)); } int main( void ) { A a(5); A b(6); C c=a+b; std::cout<<"c.m_data="<<c.m_data<<std::endl; return(0); }
type operator- ();
No. There is no default return type for functions, it must be explicitly specified in both the function declaration and in the definition. To specify no return value, return void. To return a variant type, return void* (pointer to void). Otherwise return the exact type.
A ternary operator is an operator that requires three operands, as opposed to a binary operator that requires two operands and a unary operator that requires just one operand. C++ has just one ternary operator, the conditional ternary operator: <boolean expression> ? <expression #1> : <expression #2>; If the boolean expression evaluates true, the first expression is evaluated, otherwise the second expression is evaluated. A typical usage of this operator is to return the larger (or smaller) of two values of type T: template<typename T> T max (T a, T b) {return a<b ? b : a}; template<typename T> T min (T a, T b) {return a<b ? a : b}; These are really nothing more than notational shorthand for the following: template<typename T> T max (T a, T b) {if (a<b) return b; else return a; }; template<typename T> T min (T a, T b) {if (a<b) return a; else return b;}; However, because ternary expressions are evaluated, the return value of the expression can be used in more complex expressions: int a=42, b=0; // ... int c = ((a>b ? a : b) = 1); In the above expression, whichever is the larger of a and b will be assigned the value 1 which will also be assigned to c. Thus a and c become 1 while b remains 0.
class foo { private: int m_data; public: foo (int data=0): m_data (data) {} foo (const foo& source): m_data (source.m_data) {} foo (foo& source): m_data (std::move (source.m_data)) {} // operator overloads: assign foo& operator= (const int source) { m_data = source; return *this; } foo& operator= (const foo& source) { m_data = source.m_data; return *this; } foo& operator= (foo& source) { m_data = std::move (source.m_data); return this; } // compound operator overloads: increment and assign foo& operator+= (const foo& rhs) { m_data += rhs.m_data; return *this; } foo& operator+= (const int rhs) { m_data += rhs; return *this; } };
When you overload the -- and ++ operators in C++, if you want the pre version, aka --var, simply declare the function without an argument; whereas if you want the post version, aka var--, simply declare the function with an argument of type int. class abc { public: abc& operator++(); // pre-increment form abc& operator++(int); // post-increment form ... }; abc::operator++() { ... pre increment stuff return *this; } abc::operator++(int) { ... post increment stuff return *this; }
+ += - -= * *= / /= % %= = == != <= >= & && | ^ ~ << <<= >> >>= , [] () are the basic operator in TURBO C
conditional operator , size of operator , membership operator and scope resulation operator can not be overload in c++
Because int is the most common data-type in C. Don't rely on this though, always specify the return type explicitly.
Type 'int'
:: operator can not be used in C.