Introduction to Variables in C Programming: Types, Definition, and Lvalues & Rvalues, Lecture notes of C programming

An introduction to variables in c programming, including their types (char, int, float, double, void), definition (declaration and initialization), and the concepts of lvalues and rvalues. It covers the specifications of variable names, memory allocation, and the range of values for each type.

Typology: Lecture notes

2018/2019

Uploaded on 02/26/2019

Bulgaria1999
Bulgaria1999 🇺🇸

5 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
University of Central Florida
COP 3223C
Introduction to Programming in C
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Introduction to Variables in C Programming: Types, Definition, and Lvalues & Rvalues and more Lecture notes C programming in PDF only on Docsity!

University of Central Florida

COP 3223C

Introduction to Programming in C

  • (^) A variable is nothing but a name given to a

storage area that our programs can

manipulate.

  • (^) Each variable in C
    • (^) has a specific type, which determines the size and layout of the variable's memory
    • (^) The range of values that can be stored within that memory
    • (^) The set of operations that can be applied to the variable
  • (^) char
    • (^) Typically a single octet (one byte).
    • (^) This is an integer type
  • (^) int
    • (^) The most natural size of integer for the machine
  • (^) float
    • (^) A single-precision floating point value
  • (^) double
    • (^) A double-precision floating point value
  • (^) void
    • (^) Represents the absence of type
  • (^) C programming language also allows to define

various other types of variables, which we will

cover in subsequent lectures about

  • (^) Enumeration
  • (^) Pointer
  • (^) Array
  • (^) Structure
  • (^) Union
  • (^) For this lecture, we will study only basic

variable types

  • (^) Variable Definition in C
    • (^) type must be a valid C data type including char, w_char, int, float, double, bool, or any user-defined object
    • (^) variable_list may consist of one or more identifier names separated by commas
  • (^) Variable Definition in C
    • (^) Some valid declarations are shown here
    • (^) The line int i, j, k; declares and defines the variables i, j, and k; which instruct the compiler to create variables named i, j and k of type int.
  • (^) Variable Definition in C
    • (^) For definition without an initializer
      • (^) variables with static storage duration are implicitly initialized with NULL (all bytes have the value 0)
      • (^) the initial value of all other variables are undefined
  • (^) Variable Definition in C
    • (^) A variable declaration provides assurance to the compiler that there exists a variable with the given type and name so that the compiler can proceed for further compilation without requiring the complete detail about the variable.
    • (^) A variable definition has its meaning at the time of compilation only, the compiler needs actual variable definition at the time of linking the program.
  • (^) Example
    • (^) The example, where variables have been declared at the top, but they have been defined and initialized inside the main function
  • (^) Variable Definition in C
    • (^) The same concept applies on function declaration where you provide a function name at the time of its declaration and its actual definition can be given anywhere else.
    • (^) Example
  • (^) Lvalues and Rvalues in C
    • (^) There are two kinds of expressions in C −
      • (^) lvalue
        • (^) Expressions that refer to a memory location are called "lvalue" expressions.
        • (^) An lvalue may appear as either the left-hand or right-hand side of an assignment.
      • (^) rvalue
        • (^) The term rvalue refers to a data value that is stored at some address in memory.
        • (^) An rvalue is an expression that cannot have a value assigned to it which means an rvalue may appear on the right-hand side but not on the left-hand side of an assignment.
  • (^) Lvalues and Rvalues in C
    • (^) Variables are lvalues and so they may appear on the left-hand side of an assignment.
    • (^) Numeric literals are rvalues and so they may not be assigned and cannot appear on the left-hand side.
    • (^) Take a look at the following valid and invalid statements