munotes® Sign in

Engineering Sem 2 C Programming Dec 2014 Question Paper with Solutions

Mumbai University Solved Question Papers munotes.in

C Programming

Engineering · Sem 2

Dec 2014 Examination

Previous Year Question Paper with Solution

munotes.in Mumbai

munotes.in

First published on munotes.in on 2 December 2026.

Published by munotes.in, Mumbai.

Model answers written and edited by the munotes.in editorial desk.

Passages from this volume may be quoted, in print, online or by an AI system, with credit: name munotes.in and link to this volume's page. The volume may not be reproduced as a whole. Full terms at munotes.in/content-license.

munotes.in is an independent study resource for students of the University of Mumbai. It is not affiliated with the University of Mumbai, and is not endorsed by it.

The University does not publish an official answer key for this paper. The answers in this volume are model answers, written to show how a full-mark answer is built. They are a study aid, not an authority on what an examiner marked.

The question paper reproduced here is the paper as set by the University of Mumbai at the Dec 2014 examination.

munotes.in ii
munotes.in iii
munotes.in iv
munotes.in v

The Paper as Set

The questions in this volume are the questions asked at the Dec 2014 examination, reproduced as the University of Mumbai set them, in the order it set them. Nothing has been reworded, added or left out. Only the answers are ours. See the original question paper.

Duration 3 hours  ·  Total marks 80  ·  19 questions answered

How to use this volume

Solve the paper first, under exam conditions and against the clock. Then read the answers here and mark your own. Reading a solution before attempting the question feels productive and teaches very little, because recognising an answer is not the same as being able to write one.

munotes.in vi

Q1

Q1 20 Marks

munotes.in 1

(a)Explain the difference in using call by reference and call by value methods for argument passing, for swapping 2 numbers.[8]

Answer

For full marks, cover: what a swap needs, the swap written with call by value and why it fails, the swap written with call by reference through pointers and why it works, the values in memory step by step, one program with both functions and its output, and a table of differences.

What swapping needs

To swap two numbers m and n, a third variable holds one value while the other is moved: hold = m; m = n; n = hold. Inside main( ) this is easy. The question is what happens when the swap is a separate function, because a function receives its arguments in one of two ways, and only one of them lets it change the caller's variables.

munotes.in 2

Swap with call by value

void exchange_copies(int first, int second) receives copies of m and n. Its three statements exchange the copies correctly, as the line printed inside it shows, but first and second are local variables of the function: they disappear when it returns, and m and n in main( ) never changed. A call by value cannot swap the caller's variables.

Swap with call by reference

void exchange_through_pointers(int *first, int *second) receives the addresses &m and &n. Then *first is not a copy of m but m itself, reached through its address, so hold = *first; *first = *second; *second = hold; exchanges the values stored in m and n. When the function returns, the swap remains. In C this is how call by reference is done: the addresses are passed, and the function works through them.

Program in C

#include <stdio.h>

void exchange_copies(int first, int second)

{

int hold = first;

munotes.in 3

first = second;

second = hold;

printf("Inside exchange_copies: first = %d, second = %d\n", first, second);

}

void exchange_through_pointers(int *first, int *second)

{

int hold = *first;

*first = *second;

*second = hold;

printf("Inside exchange_through_pointers: *first = %d, *second = %d\n", *first, *second);

}

int main(void)

{

int m = 15, n = 40;

printf("In main at the start: m = %d, n = %d\n", m, n);

exchange_copies(m, n);

munotes.in 4

printf("In main after call by value: m = %d, n = %d\n", m, n);

exchange_through_pointers(&m, &n);

printf("In main after call by reference: m = %d, n = %d\n", m, n);

return 0;

}

Output

In main at the start: m = 15, n = 40

Inside exchange_copies: first = 40, second = 15

In main after call by value: m = 15, n = 40

Inside exchange_through_pointers: *first = 40, *second = 15

In main after call by reference: m = 40, n = 15

Values, step by step

munotes.in 5
MomentmnThe parameters
start of main( )1540none yet
inside exchange_copies, after the swap1540first = 40, second = 15 (copies)
back in main( )1540the copies are gone
inside exchange_through_pointers, after the swap4015first holds &m, second holds &n
back in main( )4015none

Differences

PointCall by valueCall by reference
Arguments in the callexchange_copies(m, n)exchange_through_pointers(&m, &n)
Parametersint first, int secondint *first, int *second
The swap works onthe function's own copiesm and n themselves, through their addresses
munotes.in 6
PointCall by valueCall by reference
Result in main( )unchanged: 15 and 40swapped: 40 and 15
Suited toa function that only reads its inputsa function that changes its inputs

Conclusion. Swapping by call by value exchanges only the function's copies, so m and n stay 15 and 40 in main( ). Swapping by call by reference passes &m and &n, and the function exchanges *first and *second, which are m and n themselves, so main( ) sees 40 and 15. A swap function therefore needs call by reference.

munotes.in 7

This paper is locked

Get the solved papers to read this paper and every solved paper of this semester.

B.E. First Year (all branches) Semester 2 Previous Year Question Paper Solutions
B.E. First Year (all branches) Semester 2 Notes
Issue

Found an error in this volume? Report it and we will check it against the paper.

Done!