Docsity

Constants and Literals in C Programming: Types and Definitions, Lecture notes of C programming

Partial preview of the text

Download Constants and Literals in C Programming: Types and Definitions and more Lecture notes C programming in PDF only on Docsity!

University of Central Florida

COP 3223C

Introduction to Programming in C

  • (^) Constants refer to fixed values that the

program may not alter during its execution.

  • (^) These fixed values are also called literals.
  • (^) Constants can be of any of the basic data types

like an integer constant, a floating constant, a

character constant, or a string literal.

  • (^) There are enumeration constants as well.
  • (^) Constants are treated just like regular variables

except that their values cannot be modified

after their definition.

  • (^) Integer Literals
    • (^) Here are some examples of integer literals
  • (^) Integer Literals
    • (^) Following are other examples of various types of integer literals
  • (^) Floating-point Literals
    • (^) Here are some examples of floating-point literals
  • (^) Character Constants
    • (^) Character literals are enclosed in single quotes, e.g., 'x' can be stored in a simple variable of char type.
    • (^) A character literal can be
      • (^) a plain character (e.g., 'x’)
      • (^) an escape sequence (e.g., '\t’)
      • (^) a universal character (e.g., '\u02C0')
    • (^) There are certain characters in C that represent special meaning when preceded by a backslash for example, newline (\n) or tab (\t).
  • (^) String Literals
    • (^) Here are some examples of string literals
    • (^) All the three forms are identical strings
  • (^) Defining Constants
    • (^) There are two simple ways in C to define constants
      • (^) Using #define preprocessor
      • (^) Using const keyword
    • (^) The #define Preprocessor
    • (^) The const Keyword
    • (^) Note that it is a good programming practice to define constants in CAPITALS
  • (^) Defining Constants - (^) const - (^) Notice that this implementation requires the const to be inside the main function