constants (02-11-2011)
TRANSCRIPT
-
8/3/2019 Constants (02-11-2011)
1/6
1. Constants:
The quantities whose values dont change during the execution of program are
called constants. A constant value may be numeric or alphabetic.
For example: 455,45,9, Ali etc.
Types of Constants
Two main categories of constants are
1. Numeric Constant
2. Character Constant
1. Numeric Constants
Numeric Constants are of two types
(a) Integer Constant
A numeric constant is a whole number without decimal or comma. These are
the values that are counted e.g. 45,789
(b) Floating point Constant
A numeric value with a decimal point in it is called floating point constant.
These are the values that are measured e.g. 45.9,56.0 etc.
2. Character Constant
A character constant consists of a single character enclosed in single quotation
marks, e.g. 5, A etc.
Variable
The quantity whose value may change during the execution of program is
called variable.
When a variable is declared, computer assigns it a particular memory location.
The value of variable is stored in that memory location. A variable is assigned a name
that is assigned a value. Following are the rules to assign a name to a variable.
-
8/3/2019 Constants (02-11-2011)
2/6
1. A variable name begins with a letter or underscore.
2. Blank spaces are not allowed in a variable name.
3. Special symbols like +,*,&,% cant be tested in a variable name.
4. Keywords can not be used as a variable name.
5. Maximum length of characters for a variable name is 31.
For example, Total, Average, and Sum are valid variable names whereas void
is invalid because it is a keyword.
Keywords
Keywords are the reserve words that have predefined meaning in C language
and cant be used as variable names or function names. There are 32 keywords in C
language. Keywords are written in lowercase. Since C is case-sensitive language so
keywords written in uppercase are not treated as keywords. Examples included void,
int, float, and return, while etc.
Data Types
Data type refers to the type of data used in C program. Each data type
occupies a specific number of bytes in memory to store different types of values.
Different data types are:
1. Integer Variable:
A variable that holds integer type values are valued integer variables. In C
short, long and unsigned can be preceded before int data type.
An integer valuable can be declared as
Inta;
Short int x,y;
Long int sum=0
2. Floating-point Variables:
-
8/3/2019 Constants (02-11-2011)
3/6
A variable that holds decimal type values are called floating-point variables. In
C language, keyword float is used for floating-point data type. Different type
qualifiers like double and long double can be preceded before float data type. A
floating point variable can be declared as:
Float a;
Double float x,y;
Long double float, sum-0,0;
3. Character Variables:
A variable that holds a single character values are called character valuable. In
C language, keyword char is used for character data type. A character variable can
be declared as
Char a, b;
Char p=A;
-
8/3/2019 Constants (02-11-2011)
4/6
Expressions:
An expression is a combination of operators and operands (variables,
constants) that specify and calculate the value of a particular formula. For example,
a+b, y 8+5, key are different expressions.
Types of Operators:
Different types of operators include.
1. Arithmetic Operators:
In C language, there are five arithmetic operators i.e.
1. Addition (+) add type numbers e.g. 5+7=12
2. Subtraction (-) subtracts two numbers e.g. 9-3=6
3. Multiplication(*) multiplies two numbers e.g. 8*3=24
4. Division (/) divides two numbers e.g. 45/5=9
5. Modulus 7% 3=1
Precedence of Operators:
The order in which the anthemia operators are preferred is called precedence
of operators.
1. Multiplication and Division is performed first from left to right.
2. Addition and Subtraction is performed from left to right.
2. Assignment Operators:
The operator that is used to assign a value to a variable is called assignment
operator. It is represented as (-) sign. The value to be assigned can be a constant value,
a variable name of an expression. For example,
A=15;
A=x*y;
-
8/3/2019 Constants (02-11-2011)
5/6
Besides this, there are some other assignment operators like +=,=,*=,/= These
operators are used when we want to add, subtract, multiply or divide in the previous
value of variable. For example,
A=A+7; is equal to A+=7; and A=A*6; is equal to A*=6;
3. Relational Operators
Operators that compare the values of two operands (Variable or Constant) and
return a result in True of false are called relational operators.
Six relational operators in C language are;
1. Greater than > 2. Less than = 4. Less than or equal < =
5. Equal > = 6. Not equal ! =
For example, if a-8 and b=15, then a>b returns false & a!=b returns true.
4. Logical Operators:
The operators that compare two Boolean values and give result in True and
false are called logical operators.
In Boolean algebra, there are three basic logical operators. One is unary
operators NOT and two binary operators are AND and OR.
(i) Not Operator
NOT operation is a unary operation. Not of a variable is its binary
complement and is the negation of its value. For example, NOT (5>7)
return True.
(ii) AND Operator
AND operator returns true when both the Boolean values are true
otherwise it returns False. It is represented as &&, For example, 17>7
&&5
-
8/3/2019 Constants (02-11-2011)
6/6
(iii) OR Operator
OR operator returns the result true when anyone of the two Boolean values
is true otherwise it returns False. It is represented as 11
For example, 5>7117> return True.
5. Increment Operators:
The operator that increments the value of a variable by 1 is called increment
operator. It is represented as
Increment operator ++ can only be used for a single variable name and can bewritten before or after the variable name. If it is written before variable called postfix
increment. For example, ++a or a++;
6. Decrement Operators:
The operator that decrements the value of a variable by 1 is called decrement
operator. It is represented as ..
Decrement operator can only be used for a single variable name and can be
written before or after the variable name. If it is written before variable name, it is
called prefix decrement and if it is written after the variable name, it is called postfix
decrement. For example, -- a or a --;