Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
An object is an instance of a class. You create objects to access member variables and member functions of a class. The chapter discusses how to declare variables. It also discusses how to write and execute C# program. | Creating Objects An object is an instance of a class. You create objects to access member variables and member functions of a class. The chapter discusses how to declare variables. It also discusses how to write and execute C program. Chapter 2 Objectives In this chapter you will learn to fl Declare variables fl Write and execute C programs Declaring Variables A variable is a location in the memory that has a name and contains a value. The value could be an integer such as 27 a decimal such as 9.85 or a character such as L . A variable is associated with a data type that defines the type of data which can be stored in a variable. For example a variable called TennisPlayerName will ideally store characters whereas a variable called High_Score will store numbers. A program refers to a variable by its name. Naming Variables in C The following rules are used for naming variables in C Must begin with a letter or an underscore _ which may be followed by a sequence of letters digits 0-9 or underscores. The first character in a variable name cannot be a digit. Should not contain any embedded spaces or symbols such as @ - A . and . However an underscore can be used wherever a space is required like high_score. Must be unique. For example to store four different numbers four unique variable names need to be used. Uppercase letters are considered distinct from lowercase letters. Can have any number of characters. Keywords cannot be used as variable names. For example you cannot declare a variable named class because it is a keyword in C . The following are examples of valid variable names Game_level High_score This_variable_name_is_very_long The following are examples of invalid variable names score 2strank Note C is a case-sensitive language. This means that the variable TennisPlayerName is not the same as the variable tennisplayername. NIIT Creating Objects .