Session 2

| Variables and Data Types Session 2 Objectives Discuss variables Differentiate between variables and constants List the different data types and make use of them in C programs Discuss arithmetic operators Variables Data Memory Each location in the memory is unique Variables allow to provide a meaningful name for the location in memory 15 Data in memory 15 Example A, B and C are variables in the pseudocode BEGIN DISPlAY ‘Enter 2 numbers’ INPUT A, B C = A + B DISPLAY C END Variable names takes away the need for a programmer to access memory locations using their address The operating system takes care of allocating space for the variables To refer to the value in the memory space, we need to only use the variable name Constants A constant is a value whose worth never changes Examples 5 numeric / integer constant numeric / float constant ‘Black’ string constant ‘C’ Character constant Variables hold constant values The names of variables, functions, labels, and various other user defined objects are called identifiers Some correct identifier names arena s_count marks40 class_one Examples of erroneous identifiers 1sttest oh!god start. end Identifiers can be of any convenient length, but the number of characters in a variable that are recognized by a compiler varies from compiler to compiler Identifiers in C are case sensitive Identifier Names ! is invalid Guidelines for Naming Identifiers Variable names should begin with an alphabet Proper names should be avoided while naming variables The first character can be followed by alphanumeric characters A variable name should be meaningful and descriptive Confusing letters should be avoided Some standard variable naming convention should be followed while programming Keywords Keywords : All languages reserve certain words for their internal use Keywords hold a special meaning within the context of the particular language No problem of conflict as long as the keyword and the variable name can be distinguished. For . | Variables and Data Types Session 2 Objectives Discuss variables Differentiate between variables and constants List the different data types and make use of them in C programs Discuss arithmetic operators Variables Data Memory Each location in the memory is unique Variables allow to provide a meaningful name for the location in memory 15 Data in memory 15 Example A, B and C are variables in the pseudocode BEGIN DISPlAY ‘Enter 2 numbers’ INPUT A, B C = A + B DISPLAY C END Variable names takes away the need for a programmer to access memory locations using their address The operating system takes care of allocating space for the variables To refer to the value in the memory space, we need to only use the variable name Constants A constant is a value whose worth never changes Examples 5 numeric / integer constant numeric / float constant ‘Black’ string constant ‘C’ Character constant Variables hold constant values The names of variables, functions, labels, and various other user .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.