Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the confusing points of C++?

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what are the points that C++ is easy to be confused?" in the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1 compilation error

Recently, the core algorithm of a project in the company is written in C++. Due to the need to customize a function, we need to understand the code 1. 0 and then extend it. IDE chose Code::Blocks, which is cross-platform, and the compiler is GNU caterpillar, so it can run on linux systems.

When compiling the program, there are always several very typical problems, which are summarized here.

2const qualifier

The problem of const qualifier assignment is often error-prone.

For example:

Const char * pa

Char * pb

Pb = pa; / / wrong!

Pa = pb; / / ok!

Why?

One trick: look at the attributes of variables. Pa has const,pb but no const, so pa assigns values to pb, that is, more attributes are assigned to fewer attributes, which is not allowed. The other way around is fine.

3 two confusing priorities

1) an array or a pointer?

Int * pa []

Is it a pointer or an array?

Remember: [] has a higher priority than *, so it is equivalent to:

Int * (pa [])

Therefore, it is an array with the element type as a pointer.

2) function or function pointer?

Int * fp ()

The function () takes precedence over *, so it is equivalent to:

Int * (fp ())

4 who is const?

The following expressions:

Const int* pa

Int cont * pb

Int* const pc

In the last case, the pointer is const, and the first two are pointers pointing to the content const.

This is the end of the content of "what are the easy confusing points of C++"? thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report