Unit 2Data Types, Operators and Expressions
Follows IGNOU MCS-201, Unit 2
Every C program stores values and computes new values from them. This unit covers the building blocks for both: the names you may use, the types of data C can store and how much memory each needs, constants and variables, and the operators that combine them into expressions. It also explains exactly how C decides the type and value of an expression, which is where many beginner bugs come from.
In this unit you will learn to
- Form valid identifiers and recognise C’s keywords.
- Choose a suitable data type and know its size and range on a real system.
- Declare and initialise variables, and write integer, floating, character and string constants.
- Use symbolic constants, enumerations and typedef.
- Write and evaluate arithmetic, relational, logical, conditional and comma expressions.
- Use increment and decrement operators safely.
- Predict automatic type conversions and use the cast and sizeof operators.
- Apply operator precedence and associativity to evaluate mixed expressions step by step.
Sections in this unit
- 2.1Character Set, Identifiers and KeywordsLearn which characters C programs are made of, the rules for naming identifiers, and the reserved keywords that cannot be used as names.11 min
- 2.2Data Types and Their SizesUnderstand C's basic data types, how much memory each uses on modern systems, their ranges, and how short, long, signed and unsigned change them.11 min
- 2.3Variables: Declaration and InitialisationLearn what a variable is, how to declare it with a type, the two ways to give it an initial value, and why uninitialised variables are dangerous.10 min
- 2.4ConstantsWrite integer constants in decimal, octal and hexadecimal, floating constants, character constants with escape sequences, and string constants.10 min
- 2.5Symbolic Constants, Enumerations and typedefGive names to fixed values with #define, group related named integer constants with enum, and create new names for types with typedef.9 min
- 2.6Expressions, Assignment and Arithmetic OperatorsBuild expressions with operands and operators, use the assignment and arithmetic operators, and evaluate arithmetic expressions using precedence rules.11 min
- 2.7Increment and Decrement OperatorsUse the ++ and -- operators in prefix and postfix form, predict their results, and avoid undefined behaviour from modifying a variable twice.10 min
- 2.8Relational and Logical OperatorsCompare values with relational operators, combine conditions with &&, || and !, read truth tables, and use short-circuit evaluation.9 min
- 2.9Conditional and Comma OperatorsChoose between two values with the conditional operator ?:, and evaluate expressions in sequence with the comma operator.6 min
- 2.10Type Conversion and the Cast OperatorPredict how C automatically converts types in mixed expressions and assignments, and force a conversion with the cast operator.9 min
- 2.11The sizeof Operator, Shorthand Assignment and PrecedenceMeasure storage with sizeof, write compound assignments such as +=, and evaluate any expression using C's operator precedence and associativity table.11 min