Q1. Write A Short Note On IDENTIFIERS: Syntax
Q1. Write A Short Note On IDENTIFIERS: Syntax
Copy
#include <stdio.h>
int main()
{
int result;
if ( result != 0 )
printf_s( "Bad file handle\n" );
}
Once declared, you can use the identifier in later program statements to
refer to the associated value.
Syntax
identifier:
nondigit
identifier nondigit
identifier digit
nondigit: one of
_abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
digit: one of
0123456789
The first character of an identifier name must be a nondigit (that is, the first
character must be an underscore or an uppercase or lowercase letter). ANSI
allows six significant characters in an external identifier's name and 31 for
names of internal (within a function) identifiers. External identifiers (ones
declared at global scope or declared with storage class extern) may be
subject to additional naming restrictions because these identifiers have to be
processed by other software such as linkers.
Microsoft Specific
Copy
add
ADD
Add
aDD
Microsoft Specific
Do not select names for identifiers that begin with two underscores or with
an underscore followed by an uppercase letter. The ANSI C standard allows
identifier names that begin with these character combinations to be reserved
for compiler use. Identifiers with file-level scope should also not be named
with an underscore and a lowercase letter as the first two letters. Identifier
names that begin with these characters are also reserved. By convention,
Microsoft uses an underscore and an uppercase letter to begin macro names
and double underscores for Microsoft-specific keyword names. To avoid any
naming conflicts, always select identifier names that do not begin with one
or two underscores, or names that begin with an underscore followed by an
uppercase letter.
The following are examples of valid identifiers that conform to either ANSI or
Microsoft naming restrictions:
Copy
j
count
temp1
top_of_page
skip12
LastNum
Microsoft Specific
The Microsoft linker is case sensitive. You must specify all identifiers
consistently according to case.
The "source character set" is the set of legal characters that can appear in
source files. For Microsoft C, the source set is the standard ASCII character
set. The source character set and execution character set include the ASCII
characters used as escape sequences. See Character Constants for
information about the execution character set.
1. Arithmetic operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Increments and Decrement Operators
6. Conditional Operators
7. Bitwise Operators
8. Special Operators
1. Arithmetic Operators
All the basic arithmetic operations can be carried out in C. All the operators have almost the
same meaning as in other languages. Both unary and binary operations are available in
C language. Unary operations operate on a singe operand, therefore the number 5 when
operated by unary – will have the value –5.
Arithmetic Operators
Operator Meaning
* Multiplication
/ Division
% Modulus Operator
x + y
x - y
-x + y
a * b + c
-a * b
etc.,
.
#include //include header file stdio.h
void main() //tell the compiler the start of the program
{
int numb1, num2, sum, sub, mul, div, mod; //declaration of variables
scanf (“%d %d”, &num1, &num2); //inputs the operands
Integer Arithmetic
When an arithmetic operation is performed on two whole numbers or integers than such an
operation is called as integer arithmetic. It always gives an integer as the result. Let x =
27 and y = 5 be 2 integer numbers. Then the integer operation leads to the following
results.
x + y = 32
x – y = 22
x * y = 115
x % y = 2
x / y = 5
x + y = 18.0
x – y = 10.0
x * y = 56.0
x / y = 3.50
Mixed mode arithmetic
When one of the operand is real and other is an integer and if the arithmetic operation is
carried out on these 2 operands then it is called as mixed mode arithmetic. If any one
operand is of real type then the result will always be real thus 15/10.0 = 1.5
2. Relational Operators
Often it is required to compare the relationship between operands and bring out a decision
and program accordingly. This is when the relational operator come into picture. C supports
the following relationaloperators.
Operator Meaning
== is equal to
!= is not equal to
A simple relational expression contains only one relational operator and takes the following
form.
Where exp1 and exp2 are expressions, which may be simple constants, variables or
combination of them. Given below is a list of examples of relational expressions and
evaluated values.
Relational expressions are used in decision making statements of C language such as if,
while and forstatements to decide the course of action of a running program.
3. Logical Operators
C has the following logical operators, they compare or evaluate logical
and relational expressions.
Operator Meaning
|| Logical OR
! Logical NOT
Example
a > b && x = = 10
The expression to the left is a > b and that on the right is x == 10 the whole expression is
true only if both expressions are true i.e., if a is greater than b and x is equal to 10.
Logical OR (||)
The logical OR is used to combine 2 expressions or the condition evaluates to true if any one
of the 2 expressions is true.
Example
a < m || a < n
The expression evaluates to true if any one of them is true or if both of them are true. It
evaluates to true if a is less than either m or n and when a is less than both m and n.
For example
! (x >= y) the NOT expression evaluates to true only if the value of x is neither greater
than or equal to y
4. Assignment Operators
The Assignment Operator evaluates an expression on the right of the expression and
substitutes it to the value or variable on the left of the expression.
Example
x = a + b
Here var is a variable, exp is an expression and oper is a C binary arithmetic operator. The
operatoroper = is known as shorthand assignment operator
Example
x + = 1 is same as x = x + 1
a=a+1 a += 1
a=a–1 a -= 1
a = a * (n+1) a *= (n+1)
a = a / (n+1) a /= (n+1)
a=a%b a %= b
Q3. Write a program to accept principle, amount, rate of interest
& compound interest from users and calculate simple interest &
compound interest.
1. Integer int
2. Character char
5. Void void
The size and range of each data type is given in the table below
DATA TYPE RANGE OF VALUES
Integer Type :
Integers are whole numbers with a machine dependent range of values. A good
programming language as to support the programmer by giving a control on a range of
numbers and storage space. C has 3 classes of integer storage namely short int, int and
long int. All of these data types have signed and unsigned forms. A short int requires half
the space than normal integer values. Unsigned numbers are always positive and consume
all the bits for the magnitude of the number. The long and unsigned integers are used to
declare a longer range of values.
Void Type :
Using void data type, we can specify the type of a function. It is a good practice to avoid
functions that does not return any values to the calling function.
Character Type :
A single character can be defined as a defined as a character type of data. Characters are
usually stored in 8 bits of internal storage. The qualifier signed or unsigned can be explicitly
applied to char. While unsigned characters have values between 0 and 255, signed
characters have values from –128 to 127.
Size and Range of Data Types on 16 bit machine.
Where v1, v2, v3 are variable names. Variables are separated by commas. A declaration
statement must end with a semicolon.
Example:
Int sum;
Int number, salary;
Double average, mean;
Character char
Signed Short Integer signed short int (or) short int (or) short
Signed Long Integer signed long int (or) long int (or) long
here type represents existing data type and ‘identifier’ refers to the ‘row’ name given to
the data type.
Example:
Here salary symbolizes int and average symbolizes float. They can be later used to declare
variables as follows:
Therefore dept1 and dept2 are indirectly declared as integer datatype and section1 and
section2 are indirectly float data type.
The second type of user defined datatype is enumerated data type which is defined as
follows.
Do while loop
Do while loop statement allows you to execute code block in loop body at least one. Here is do while loop syntax:
view source
print?
1.do {
2. // statements
view source
print?
01.#include <stdio.h>
02.void main(){
03. int x = 5;
04. int i = 0;
06. do{
07. i++;
08. printf("%d\n",i);
10.
11.}
The program above print exactly 5 times as indicated in do while loop body
1
2
3
4
5