Q&A [3]:變數宣告


Posted by clins210 on 2020-11-23

In programming language C, we have different type of variable, such as

  • private
  • public

The "private" means you can use this kind of variables in the specific blocks. Once you move out the block, you can't use this in your code.

put coding here

Otherwise, the "public" type variable means all of the people who knows this code name can call it to do something.

class Count{ 
public: 
    /*numberPub can be used anywhere in the class Count */ 
    int numberPub; 

    /*This will return our private variable, numberPri. This way, we can return the variable, but we do not have to worry about access, such as a user modifying the value when they shouldn't. */ 
    int getNumberPri(); 

private: 
    /*numberPri cannot be used anywhere in the class Count. If we want to use numberPri in Count, we must use getNumberPri() to access it*/ 
    int numberPri; 
};

Citation:

  1. https://www.quora.com/What-is-private-and-public-in-C

#Variables #C #private #public







Related Posts

到底什麼是建構函式?  我不知道

到底什麼是建構函式? 我不知道

《鳥哥 Linux 私房菜:基礎篇》Chapter 07 - Linux 磁碟與檔案系統管理

《鳥哥 Linux 私房菜:基礎篇》Chapter 07 - Linux 磁碟與檔案系統管理

[計算機網路03] Web 與 HTTP 協定的應用層結構

[計算機網路03] Web 與 HTTP 協定的應用層結構


Comments