C Ans
C Ans
CAP101
DOA: 23/08/2010
DOS: 06/09/2010
Declaration:
I declare that this assignment is my individual work. I have not copied from any other student’s work or
from any other source except where due acknowledgment is made explicitly in the text, nor has any part
been written for me by another person.
Evaluator’s comments:
_____________________________________________________________________
PART - A
Question 1:-Explain
the difference between
Associativity and Precedence with the help of an
example?
Answer:- ASSOCIATIVITY: -Associativity refers, when
in an expression there are two types of operands that
have same priority then there is a problem occur.
Associativity is used to overcome from such type of
Page | 1
situation. Associativity can be of two types first one left-
to-right and second one is right-to-left.
Left-to-right Associativity means the left operands should
not have fixed value. Value can be dynamically edited to
it later in the program.
Similarly, Right-to-left Associativity means the right
operands should not have fixed value too and it can be
dynamically edited to it later.
For example:
• Unary operators
• Binary operators
• Ternary operators
Each operator has given priority. All operators are follows
the priority principle in any expression. Priority specified
which defines the execution order of the expression.
Some of these operators are given below with their
priority-
Priority Operators Description
1st * Multiplication
2nd / Divide
Page | 2
3rd % Modular
4th + Add
5th - Subtraction
6th = Assignment
For example: x = 6 + 8 * 4 / 2 + 4 -2 / 2;
x = 25;
int z;
x = z;
Page | 3
For example:-In C, to convert an integer values to a float
or char data type where integer usually has 16-bits,float
has 32-bits and char has 8-bit.
Explicit type conversion allows converting any data type
into any data type.
For example: -
Short x=50;
Int z;
z = (int) a; //or
z = int a;
Similarly -
y=x++; //postfix operator
Then y=10
//do this;
//and this;
//and this;
Page | 6
}
Page | 7
Signed integer can store negative as well as positive
integer. By default an integer is a signed integer.
For example: int a; // it is a signed integer.
PART - B
Question 4: - Write a program that will examine each
character in a character type array and write the ASCII
equivalent of each character. Size of the array is known
in advance by the integer variable n.
Page | 8
Answers: -
OUTPUT: -
Page | 9
Question 5: - Write a program to display the day of
week according to the day no. entered by the user.
Answer:-
OUTPUT: -
Page | 10
Question 6:- Write a program that receives a multi-word
string and prints it in the form of one word per line.
Answer: -
OUTPUT: -
Page | 11
Page | 12