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

An introduction to constants and literals in the c programming language. It covers the concept of constants as fixed values, their different types such as integer, floating-point, character, and string literals, and the ways to define constants using the #define preprocessor and the const keyword.

Typology: Lecture notes

2018/2019

Uploaded on 02/26/2019

Bulgaria1999
Bulgaria1999 🇺🇸

5 documents

1 / 13

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

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