0% found this document useful (0 votes)
21 views

2 Basic Data Types and Operators

Chapter 2 covers C's basic data types, operators, and expressions. It discusses variables, constants, and the basic types available in C like integer and floating point. The chapter also explains that a variable's type determines what values it can take on and what operations can be performed on it. Picking the right type for a variable depends on the values and operations that will be used with that variable.

Uploaded by

gdskumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

2 Basic Data Types and Operators

Chapter 2 covers C's basic data types, operators, and expressions. It discusses variables, constants, and the basic types available in C like integer and floating point. The chapter also explains that a variable's type determines what values it can take on and what operations can be performed on it. Picking the right type for a variable depends on the values and operations that will be used with that variable.

Uploaded by

gdskumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Chapter 2: Basic Data Types and

Operators
The type of a variable determines what kinds of values it may take on. An operator
computes new values out of old ones. An expression consists of variables, constants, and
operators combined to perform some useful computation. In this chapter, we'll learn
about C's basic types, how to write constants and declare variables of these types, and
what the basic operators are.

As Kernighan and Ritchie say, ``The type of an object determines the set of values it can
have and what operations can be performed on it.'' This is a fairly formal, mathematical
definition of what a type is, but it is traditional (and meaningful). There are several
implications to remember:

1. The ``set of values'' is finite. C's int type can not represent all of the integers; its
float type can not represent all floating-point numbers.
2. When you're using an object (that is, a variable) of some type, you may have to
remember what values it can take on and what operations you can perform on it.
For example, there are several operators which play with the binary (bit-level)
representation of integers, but these operators are not meaningful for and may not
be applied to floating-point operands.
3. When declaring a new variable and picking a type for it, you have to keep in mind
the values and operations you'll be needing.

In other words, picking a type for a variable is not some abstract academic exercise; it's
closely connected to the way(s) you'll be using that variable.

You might also like