TAILIEUCHUNG - Applying Scope Turailment

Tham khảo tài liệu 'applying scope turailment', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Applying Scope You have seen in some of the examples that you can create a variable inside a method. The variable comes into existence at the point where a statement defines it and subsequent statements in the same method can then use the variable. In other words a variable can be used only after it has been created. After the method has finished the variable disappears completely. If a variable can be used at a particular location in a program the variable is said to be in scope at that location. To put it another way the scope of a variable is simply the region of the program in which that variable is usable. Scope applies to methods as well as variables. The scope of an identifier of a variable or method is linked to the location of the declaration that introduces the identifier into the program as you ll now learn. Defining Local Scope The opening and closing curly braces that form the body of a method define a scope. Any variables you declare inside the body of a method are scoped to that method they disappear when the method ends and can be accessed only by code running within that method. These variables are called local variables because they are local to the method in which they are declared they are not in scope in any other method. This arrangement means that you cannot use local variables to share information between methods. Consider this example class Example void firstMethod int myVar . void anotherMethod myVar 42 error - variable not in scope . This code would fail to compile because anotherMethod is trying to use the variable myVar which is not in scope. The variable myVar is available only to statements in firstMethod. Defining Class Scope The opening and closing curly braces that form the body of a class also create a scope. Any variables you declare inside the body of a class but not inside a method are scoped to that class. The proper C name for the variables defined by a class is fields. Unlike local variables you can use fields to share .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.