Knowlet

Unit III: Constants, Variables and Data Types


1. Character Set and C Tokens

The Character Set includes all characters that the C compiler can recognize, such as letters (A-Z, a-z), digits (0-9), and special characters.

C Tokens are the smallest individual units in a program. These include:

  • Keywords: Reserved words with predefined meanings.
  • Identifiers: Names given to program elements.
  • Constants: Fixed values that do not change.
  • Operators: Symbols for mathematical or logical operations.

2. Keywords and Identifiers

Keywords are reserved words that have a special meaning to the compiler and cannot be used as variable names (e.g., int, float, if).

Identifiers are names used for variables, functions, and arrays.

  • They must start with a letter or an underscore.
  • Only letters, digits, and underscores are allowed.
  • They are case-sensitive.

3. Constants and Variables

Constants are values that remain unchanged during program execution. These can be numeric (integer, real) or character constants.

Variables are identifiers used to store data values that can change during execution.

  • Declaration: Variables must be declared before use, specifying their data type.
  • Assigning Values: Values are assigned using the assignment operator (=).
  • Symbolic Constants: Defined using the #define preprocessor to assign a name to a constant value.

4. Data Types and Declarations

Data Types specify the type of value a variable can store.

  • Primary Data Types: int (integer), float (real), char (character), and double (double-precision real).
  • Declaration: All variables must be declared to inform the compiler about the storage space required.

5. Operators and Expressions

Operators are symbols that trigger an action when applied to variables and constants.

Operator Category Operators Description
Arithmetic +, -, *, /, % Perform basic math like addition and modulus.
Relational <, >, <=, >=, ==, != Compare two values for true/false results.
Logical &&, ||, ! Combine multiple conditions.
Assignment = Store a value in a variable.
Increment/Decrement ++, -- Increase or decrease a value by 1.
Conditional ? : A shorthand for simple if-else statements.

Arithmetic Expressions are combinations of variables, constants, and operators evaluated according to rules of precedence.

Exam Tips

  • Modulus Operator (%): Remember it only works with integers and returns the remainder.
  • Case Sensitivity: Identifiers like 'Total' and 'total' are different in C.
  • Symbolic Constants: Use #define for values like PI (3.14) to make code readable and easy to maintain.

Frequently Asked Questions

Q1: What is a keyword?
A keyword is a word reserved by the C language for specific purposes (like int for integers) and cannot be used as a name for variables.

Q2: What is the difference between a constant and a variable?
A constant's value is fixed and cannot be changed during the program, whereas a variable acts as a container whose content can be modified.

Did this resource help you study?

Share feedback or report issues to help improve this resource.