1.c++ Data Type customization:
#include <iostream> int main () {typedef char NAME[20]; Name A,b;std::cout<<typeid (a). Name () <<typeid (b). Name (); Std::cin.get (); return 0;}
typeID (variable name). Method name = = Data type of the output variable
Another way to define this:
#include <iostream> int main () {typedef struct SU{CHAR name[10];int age;}; Su n;std::cout <<typeid (n). Name () <<std::endl;std::cin.get (); return 0;}
2. Defining bit fields
#include <iostream> int main () {struct bs{unsigned a:1;unsigned b:3;unsigned c:4;} bit,*pbit;//defines the bit and pointer to bit pbitbit.a=1;bit.b=7;bit.c=15;printf ("%d,%d,%d\n", bit.a,bit.b,bit.c);p bit=&bit; pbit->a=0;pbit->b&=3;pbit->c|=1;printf ("%d,%d,%d\n", pbit->a,pbit->b,pbit->c); std:: Cin.get (); return 0;}
Nameless bit fields are not available.
struct K {int a:1 int:2/* The 2-bit cannot use */int b:3 int C:2};
3. Calculate the run time of the program
#include <iostream> #include <ctime> int main () {clock_t start,end;start=clock (); struct bs{unsigned a:1;uns igned b:3;unsigned C:4;} bit,*pbit;bit.a=1;bit.b=7;bit.c=15;printf ("%d,%d,%d\n", bit.a,bit.b,bit.c);p bit=&bit;pbit->a=0;pbit-> b&=3;pbit->c|=1;printf ("%d,%d,%d\n", pbit->a,pbit->b,pbit->c); End=clock ();//std::cout<< ( Double) (End-start)/clocks_per_sec;std::cout <<start;std::cout <<end;std::cin.get (); return 0;}
This article is from the "Wang Nimei Adult Road" blog, reprint please contact the author!