munotes® Sign in

Engineering Sem 2 C Programming Dec 2017 - R16 Question Paper with Solutions

Mumbai University Solved Question Papers munotes.in

C Programming

Engineering · Sem 2

Dec 2017 - R16 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 2017 - R16 examination.

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

The Paper as Set

The questions in this volume are the questions asked at the Dec 2017 - R16 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  ·  17 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 v

Q1

Q1 20 Marks

munotes.in 1

a)Define union. Compare structure and union.[4]

Answer

For full marks, cover: a definition of a union with its syntax, how its members share memory, its size, a comparison with a structure point by point, and a program that shows both.

Union

A union is a user-defined type, declared with the keyword union, whose members all begin at the same address and share one block of memory:

union value { int whole; double real; char text[8]; };

The union is as large as its largest member (here 8 bytes), and only one member holds a meaningful value at a time: storing into v.real overwrites what v.whole held. A union saves memory when a variable holds one of several kinds of value, never two at once.

Structure and union compared

PointStructureUnion
Memory of membersseparate, one after anothershared, all at the same address
Sizeabout the sum of the members, with paddingthe largest member, with padding
munotes.in 2
PointStructureUnion
Members valid togetherallone, the last written
Changing one memberleaves the others alonechanges what the others read
Example size here4 + 4 padding + 8 + 8 = 24 bytes8 bytes

Program in C

#include <stdio.h>

union value {

int whole;

double real;

char text[8];

};

struct record {

int whole;

double real;

char text[8];

};

int main(void)

munotes.in 3

{

union value v;

printf("sizeof(union value) = %d, sizeof(struct record) = %d\n", (int)sizeof(union value), (int)sizeof(struct record));

v.whole = 42;

printf("v.whole = %d\n", v.whole);

v.real = 3.75;

printf("v.real = %.2f (the int stored earlier is overwritten)\n", v.real);

printf("&v.whole == &v.real: %s\n", (void *)&v.whole == (void *)&v.real ? "yes" : "no");

return 0;

}

Output

sizeof(union value) = 8, sizeof(struct record) = 24

v.whole = 42

v.real = 3.75 (the int stored earlier is overwritten)

&v.whole == &v.real: yes

munotes.in 4

Conclusion. A union is declared like a structure, but its members share one memory block the size of the largest member, so only the last member written is valid. A structure gives each member its own memory and keeps all values together. Here the union takes 8 bytes against 24 for the same members in a structure.

munotes.in 5

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!