"Entertainment to" the secret of the C + + language cannot be said

Source: Internet
Author: User

Everyone loves C + +, isn't it?


C + + has a rich template library, such as<map><stack><queue><ext\pb_ds\priority_queue.hpp> Really loved Ah, but who knows, in the innermost heart of C, but also hidden those who can not say the secret.

SECRET _1 (array magic, regular array with a mad heart)

Let's look at a few lines of code like this

1  for (int i=1; i<=n;i++)   scanf ("%d",&a[i]); 2  for (int i=1; i<=n;i++)   printf ("", A[i]);

Comfortable, huh? This is the cow. ), that's all for today, thank you all (go back and say)

// input 1 2 3 4 5 // the output 1 2 3 4 5

This you do not understand the excuse, as a (Blablabla) ... We should get to the chase quickly.

We also have a code, as follows.

 for (int i=1; i<=n;i++)   printf ("", I[a]);
// the output 1 2 3 4 5

Oh, my God! Is there something wrong with my compiler?

In fact, this involves the manipulation of array pointers.

In code Snippet 1, there is

printf ("%d", A[i])// actually array a[] can also be seen as a int* typea//  The operation at this time is equivalent to printf ("%d", (A+i));

So, no, just say it? = = "i[a]== (i+a) = = (a+i) ==a[i];

secret_2 (the symbol of terror tends to be)

(Horror Story atmosphere) Yet many years ago, there was a symbol of horror! His name tends to be, about his record, probably like this.

He has a common face: "<--" This is the great demon!

He's probably been used in this way.

1    Cin>>N; 2     while (0<--N) {3        cout<<n<<""; 4    }

We have

// input 5 // Output 4 3 2 1

Powerful, huh?

It is said that he has a brother who is fast tending to

1    Cin>>N; 2     while (0<----N) {3        cout<<n<<""; 4    }

And a strong father, accelerating toward

1    Cin>>N; 2     while (0<------N) {3        cout<<n<<""; 4    }

There is also a fabulous uncle, the speed of light tends to

1    Cin>>N; 2     while (0<----------N) {3        cout<<n<<""; 4    }

The ambition of their generation was to become a swift force (speed FORCE,DC Comics,flash) tended to

   Cin>>N;     while (0<--------------------------------------------------N) {       cout<<n<< " " ;   }

Haha said so much of the original people are I cheated!

The first usage tending to "<--" is equivalent to:

   Cin>>N;   N--;     while (n>0) {       cout<<n<<"";        --N;   } // haha, are you cheated? 

Secret_3 (bugs present in the compiler)

We have the code:

int n=3cout<<"sizeof (n) ="<<sizeof(n+ +) <<"\ n"<<n;

It turned out not.

4

5

But

4

4

Why is it?

It's strange.

Edit until 2015.5.30->19:19

"Entertainment to" the secret of the C + + language cannot be said

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.