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

C Ans

This homework submission summarizes the student's responses to 6 questions on topics relating to C programming. It includes explanations of associativity vs precedence, implicit vs explicit type conversion, differences between various operators and programming concepts, and code snippets to print ASCII values of a character array, display the day of the week from a day number, and print words from a multi-word string one per line. The submission contains the student's name, course details, date of allotment, and date of submission.
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)
78 views

C Ans

This homework submission summarizes the student's responses to 6 questions on topics relating to C programming. It includes explanations of associativity vs precedence, implicit vs explicit type conversion, differences between various operators and programming concepts, and code snippets to print ASCII values of a character array, display the day of the week from a day number, and print words from a multi-word string one per line. The submission contains the student's name, course details, date of allotment, and date of submission.
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/ 12

*Homework1*

CAP101
DOA: 23/08/2010
DOS: 06/09/2010

Homework Title / No. : _____________1__________________Course Code: 1604::MCA

Course Instructor: ______________________ Course Tutor (if applicable): ____________

Date of Allotment: __23-08-2010____________ Date of submission: ___06-09-2010_________

Student’s Roll No._____53_______________ Section No. : _______D3002_________________

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.

Student’s Signature: Surendra Chauhan

Evaluator’s comments:
_____________________________________________________________________

Marks obtained: ___________ out of ______________________

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:

x = 8 / 4 * 6; //both operators have same priority (Left-to-right)

x = y = z; //both assignment have same priority (Right-to-left)

PRECEDENCE: - In C programming language there are


several new types of operators added. Operators are
those that specify an evaluation to be executed or to be
performed on one of the following-

• 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;

Question2:- conversion Differentiate between


implicit and explicit type?
Answer: - Implicit Type Conversion: - The implicit
type conversion is also known as automatic type
conversion. Implicit conversion does not require any type
of operator. It is automatically executed when a value is
copied to another compatible data type.
For example: - short x=50;

int z;

x = z;

Here the value of short is transferred to int without using


any type casting operator. This is also known as standard
conversion.

• Float to int conversion cause loss of fractional part.

• Long int to int cause losing data.


Explicit Type Conversion: - In c programming
language to specify that an expression’s value should be
converted to a different data type.

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;

Question 3:-Differentiate between the following-

1. Prefix and Postfix increment operator.


2. Assignment and Equal to operator.
3. Expression and Statement.
4. Identifiers and Keywords.
5. Signed and Unsigned integers.
Answer:-
*Prefix and Postfix increment operator*
The increment operator is represented by + +. The major
difference between prefix and postfix operator is prefix
increment operator notation appear before operands and
the postfix increment operator is appear after the
operands. Here the main purpose of using prefix and
postfix operator is the prefix operator increase the value
Page | 4
to its associated operands first then use that particular
operands, other hand postfix operands take place first
then increase its value.
Example-
Int x, y;
x=10;
y=++x; //prefix operator.

Then the value of y = 11;

Similarly -
y=x++; //postfix operator

Then y=10

*Assignment and Equal to operator*


Assignment: - The Assignment operator is used to
assign the value. The value is to be assign to the right-
hand operand to the left-hand side operands. In
Assignment operator the right-hand side is a source and
left-hand side is destination.
The assignment operators in C programming can both
transfer and assign values in a single operation. C
programming provides the following Assignments
operators some of them as follows –
= *= /= %= += –= <<= >>= &= ^= |=

For example: x = 5; //assign 5 to x

Equal-to: - The other operator is Equal to operator. This


operator is used to compare two operands. Equal to be a
Page | 5
mathematical symbol which is used to indicates the
equality between two or more operands.
For example: x = y; //Equal to operator

*Expression and Statement*


Expression: - Expression means, it is a finite collections
of symbols or combinations of symbols that are well-
defined or well-formed according to the rules applicable
in the context. The symbols may be variables, Constance,
relations or operations.
For example: - 7 + 5 * ((- 4) + 3 / 2) //it is a mathematical
expression.

Statements: - Other-hand Statements are used to


control the flow of any program execution in
programming languages. There are several types of
statements some of them are as follows.
If statement While statement
For statements Do-while statement
Continue statement Break statement
Return statement Compound statement
Expression statement Go to statement

Example: - for (initialization; condition testing; increment/decrement)

//do this;

//and this;

//and this;

Page | 6
}

*Identifiers and keywords*


Identifiers: - identifiers are those which are declare by
the user. Identifiers are differing from the keywords in
spell and case. We can create identifiers by specifying it
in declaration of a variable data type.
For example: int name; //name is a identifier for an integer variable

Identifiers may be A – Z, a – z, 0 – 9, or may be _


All identifiers must be in lower case or in upper case, no
space between them like emp_name, and always start
with alphabets.
Keywords: - Keywords are those words that have some
special meaning to the C compiler. We can’t use them as
a variable name. Keywords are also known as ‘reserved
words’. There are basically 32 keywords in C
programming, which are as follows –
int float char long double else break for
goto if do default static while void continu
e
union case switch struct enum register typedef Extern
return unsigne short sizeof volatile static const auto
d

*Signed and unsigned integers*


Signed integer: - It is a special type of integer which
occupies an extra bit to store the sign of the integer,
hence reducing the total capacity of the integer.

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.

Unsigned integer: - unsigned integer is a special type


of integer which can store double amount of the bit that
can be stored by a normal integer. It cannot store
negative integer.
For example: unsigned int a; //unsigned 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

You might also like