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 is the difference between C++ function calls and Struct and CLass

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "what is the difference between C++ function calls and Struct and CLass". 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!

I. structural review

Structure: the custom data type is defined by Struct regardless of the structure in C++. Compared with the structure in C, the structure in C++ not only has member variables, but also defines member functions (or methods).

Code:

Struct Student {int number; / / member variable char name; / / member variable void num () / member function (method) {number++;}}

The influence of three methods of calling function on the value of structure member variable:

1. Call by passing value

A way to call "structure variable" as a function parameter

/ / void func (Student temp) / / "structure variable" is called as a function parameter (value passing) {temp.number = 2000; strcpy_s (temp.name, sizeof (temp.name), "lisi"); / / by adding monitoring, we can see that the memory address of the formal parameter structure variable temp has changed to 0x00d7fbe4 return;} int main () {Student student Student.number = 1001; strcpy_s (student.name, sizeof (student.name), "zhangsan"); func (student); / / by adding monitoring, you can see that the memory address of the argument structure variable student is 0x00d7fd20 cout

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

Development

Wechat

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

12
Report