0% found this document useful (0 votes)
73 views4 pages

Indian Institute of Technology, Kharagpur: Department of Computer Science and Engineering

This 3-sentence summary provides the key details about the document: The document appears to be a test paper for a class on Programming and Data Structures that was given on October 27, 2016 at IIT Kharagpur to 681 students, with questions worth 20 total marks including writing C code for various tasks like defining a complex number structure, pointer operations, dynamically allocating an array, and a function to compare dates stored in a structure.

Uploaded by

Subhajit Bag
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views4 pages

Indian Institute of Technology, Kharagpur: Department of Computer Science and Engineering

This 3-sentence summary provides the key details about the document: The document appears to be a test paper for a class on Programming and Data Structures that was given on October 27, 2016 at IIT Kharagpur to 681 students, with questions worth 20 total marks including writing C code for various tasks like defining a complex number structure, pointer operations, dynamically allocating an array, and a function to compare dates stored in a structure.

Uploaded by

Subhajit Bag
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Indian Institute of Technology, Kharagpur

Department of Computer Science and Engineering


Class Test 2, Autumn 2016-17
Programming and Data Structure (CS 11001 / CS 10001)
Students: 681 Date: 27-Oct-16
Full marks: 20 Time: 7:00pm–8:00pm

Answer the questions in the spaces provided on the question sheets. You may use the last
page of this booklet for your rough work. No other supplementary sheets will be given to you.

Roll Number Section

Name

Question: 1 2 3 Total
Full marks: 10 4 6 20
Marks Obtained:

1. (10 marks) Write C statements (corresponding to a program segment) for the followings:
(a) Define a structure for representing a complex number, and declare a variable x of that
data-type (i.e. using defined structure).

(b) Write a function named swap(.) which exchanges values of two integer variables whose
location/address is passed as arguments to it.

1
(c) Dynamically allocate an array of 100 integers to a pointer to an int data type.

(d) Declare a pointer ptr of an int variable and also an integer variable k. Assign the
address of k to ptr.

(e) Suppose p is a pointer to an integer variable and a is an array of integers. Set the
address of the first element of the array a to p. Write the expression for accessing a[i]
using p.

2. (4 marks) What will be printed when the following program statements / segments will
execute?
(a)
int *x, y;
int a[6]={0,1,2,3,4,5};
x=a+2;
y=a[0]+*x;
printf ("y = %d, value=%d", y, *(a+4));
(b)
void compute(int *a, int n) {
int i;
for (i=1;i<n;i++)
a[i]=a[i-1]+a[i];
}

main() {
int b[4]={10,20,30,40};
compute(b,4);
printf("Value=%d \n", b[3]);
}

Page 2
3. (6 marks) Define a structure for storing date with components day, month and year as
integers within it. Write a C function that takes two dates d1 and d2 as arguments (using
the same structure defintion). The function returns 1 if d1 is older than d2, -1 if d1 is more
recent than d2, otherwise 0.

Page 3
[Extra page for rough work]

Page 4

You might also like