C/C ++ basic pen question 1.1.1 (operator ten questions), 1.1.1 ten questions

Source: Internet
Author: User

C/C ++ basic pen question 1.1.1 (operator ten questions), 1.1.1 ten questions

This article seems to be a problem, which is intended to cause thinking and memories. The topic is an operator. In addition, there is no special logical relationship between these questions. I just asked them when I thought of them, but can you just answer that question ?.

Operator, which we will use in every program and is also the most basic skill. This series of C/C ++ basic pen questions is a series of blog posts without outline and regularity.

Why is it like this? Because the author is a scum, he can only learn one point, and strive to be plain, a fool, but not lose the main line.

1.0 is written in byte alignment. If you have not read it, you can stamp it here. 1.1 write the content related to operators. You are the "friends" most "familiar ".

First, I would like to ask you a few questions first?

1. What operators are in your mind, sorted by priority?

2. What is the difference between malloc/free and new/delete? (I have no questions !)

3. Let you write an overloaded function ++ I, I ++. How do you write it?

Here, you may like to read programs.

4. Check a program.

#include<iostream>using namespace std;int main(){    int x=3;    cout<<x+x%2==1<<endl;     return 0;}

Check whether the output result of this program is the same as what you think? Have you been pitted?

5. Let's see another one?What's different from what you think?

#include<iostream>using namespace std;int main(){    int x=3;    cout<<((x+x%2)==1)<<endl;    cout<<(x+(x%2==1))<<endl;return 0;}
If you keep making mistakes or are basically wrong, then you will be as miserable as you are. In addition, where did these questions come from? In fact, I made some minor mistakes when I used ACM. In fact, I just want to give priority to this question.

6. Is it a bit difficult to feel the nausea of commas and parentheses?

#include<iostream>using namespace std;void fun0(int x,int y ,int z){  cout<<x<<" "<<y<<" "<<z<<endl;  int a=2,b=3,c=7;  x=a*b,c;  y=(a*b+z,z=c);  cout<<x<<" "<<y<<" "<<z<<endl;}void fun1(int x,int y,int z){  cout<<x<<" "<<y<<" "<<z<<endl;  int a=2,b=3,c=7;  y=(x=a+b+z),(z=b+c);  cout<<x<<" "<<y<<" "<<z<<endl;}void fun2(int x,int y,int z){  cout<<x<<" "<<y<<" "<<z<<endl;  int a=2,b=3,c=7;  y=((x=a+b+z),(z=b+c));  cout<<x<<" "<<y<<" "<<z<<endl;}int main(){    int x,y,z;    fun0(x,y,z);    fun1(x,y,z);    fun2(x,y,z);}
Now let's think about how to make the previous questions more harmonious.

For the sake of harmony, I still want to ask some questions about YES OR NO?

7. We use % for the remainder operation. % can only be applied to positive integers, right?

8. domain operator: we often use this operator. Can I reload it?

9. When the operator overload is used as a non-member function overload, must it be defined as a friend function?

10. Must operators be symbols? (That is, can only be +,-, *,/,:, and so on ?)

If you think that the question I asked is unreasonable, well, it is indeed true. If you do not pursue the details, it is very unreasonable. (In fact, you are not pursuing basic work)

If you have any idea about the above ten questions, you can raise them in the comments so that other friends can see them and explore them together.

As for the so-called explanations and standard answers, I will mention them in 1.1.2. When will 1.1.2 come out? Tomorrow or the day after tomorrow? I am very annoyed because I have changed my requirements during my internship! Ah... I'm not sure.




C language pen questions, explanations

Answer:
33
69

Explanation:
First, p = a means that p points to the address of array a (the first element position)
* P = 10
P ++ indicates that the address of p is returned first and then p is used for auto-increment calculation.
++ P indicates that the address of p is returned after the auto-increment operation is performed on p.
Therefore, * p ++ * ++ p = (* p ++) + (* ++ p) is equal to 10 + 23 = 33.
Note that * p = 11 after the last sentence
So * ++ p + 50 = (* ++ p) + 50 = 19 + 50 = 69

Note the difference between p ++ and ++ p.
If I have been playing for so long, can I add more points? If you have any questions, just ask me.

In C language, the arithmetic operator object must be an integer operator?

%
A modulo operation is the remainder in mathematics. This operation must be an integer.
 

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.