12 一个给定的数值由左边开始升位到右边第 N 位,如00101 == 0100或者0001 00114 == 0011 0000请用 C 或者 C++或者其他 X86 上能运行的程序实现。----------------------------------------------------------------------------------------------------------------附加题(只有在完成以上题目后,才获准回答)In C++, what does "explicit" mean? what does "protected" mean?explicitC++ SpecificThis keyword is a declaration specifier that can only be applied toin-class constructor declarations. Constructors declared explicit will notbe considered for implicit conversions. For example:class X {public:explicit X(int); //legalexplicit X(double) { //legal // ... }};explicit X::X(int) {} //illegalAn explicit constructor cannot take part in implicit conversions. It canonly be used to explicitly construct an object. For example, with the classdeclared above:void f(X) {}void g(int I){f(i); // will cause error}void h(){X x1(1); // legal}The function call f(i) fails because there is no available implicitconversion from int to X.Note It is meaningless to apply explicit to constructors with multiplearguments, since such constructors cannot take part in implicit conversions.END C++ SpecificprotectedC++ Specific —protected: [member-list]protected base-classWhen preceding a list of class members, the protected keyword specifiesthat those members are accessible only from member functions and friends ofthe class and its derived classes. This applies to all members declared upto the next access specifier or the end of the class.When preceding the name of a base class, the protected keyword specifiesthat the public and protected members of the base class are protectedmembers of the derived class.Default access of members in a class is private. Default access of membersin a structure or union is public.Default access of a base class is private for classes and public forstructures. Unions cannot have base classes.For related information, see public, private, friend, and Table of MemberAccess Privileges.END C++ SpecificExample// Example of the protected keywordclass BaseClass {protected: int protectFunc();};class DerivedClass : public BaseClass{ public:int useProtect() { protectFunc(); } // protectFunc accessible fromderived class};void main(){BaseClass aBase;DerivedClass aDerived;aBase.protectFunc(); // Error: protectFunc not accessibleaDerived.protectFunc(); // Error: protectFunc not accessible in derivedclass } How do you code an infinite loop in C?
12 一个给定的数值由左边开始升位到右边第 N 位,如
0010<<1 == 0100
或者
0001 0011<<4 == 0011 0000
请用 C 或者 C++或者其他 X86 上能运行的程序实现。
-----------------------------------------------------------------------------
-----------------------------------
附加题(只有在完成以上题目后,才获准回答)
In C++, what does "explicit" mean? what does "protected" mean?
explicit
C++ Specific
This keyword is a declaration specifier that can only be applied to
in-class constructor declarations. Constructors declared explicit will not
be considered for implicit conversions. For example:
class X {
public:
explicit X(int); //legal
explicit X(double) { //legal // ... }
};
explicit X::X(int) {} //illegal
An explicit constructor cannot take part in implicit conversions. It can
only be used to explicitly construct an object. For example, with the class
declared above:
void f(X) {}
void g(int I)
{
f(i); // will cause error
}
void h()
{
X x1(1); // legal
}
The function call f(i) fails because there is no available implicit
conversion from int to X.
Note It is meaningless to apply explicit to constructors with multiple
arguments, since such constructors cannot take part in implicit conversions.
END C++ Specific
protected
C++ Specific —>
protected: [member-list]
protected base-class
When preceding a list of class members, the protected keyword specifies
that those members are accessible only from member functions and friends of
the class and its derived classes. This applies to all members declared up
to the next access specifier or the end of the class.
When preceding the name of a base class, the protected keyword specifies
that the public and protected members of the base class are protected
members of the derived class.
Default access of members in a class is private. Default access of members
in a structure or union is public.
Default access of a base class is private for classes and public for
structures. Unions cannot have base classes.
For related information, see public, private, friend, and Table of Member
Access Privileges.
END C++ Specific
Example
// Example of the protected keyword
class BaseClass {
protected: int protectFunc();
};
class DerivedClass : public BaseClass
{ public:
int useProtect() { protectFunc(); } // protectFunc accessible from
derived class
};
void main()
{
BaseClass aBase;
DerivedClass aDerived;
aBase.protectFunc(); // Error: protectFunc not accessible
aDerived.protectFunc(); // Error: protectFunc not accessible in derived
class } How do you code an infinite loop in C?