UE17CS151: Pes University
UE17CS151: Pes University
Write functions which can be passed as the argument for the callback compare of sort_rect which will
arrange the rectangles
i) in the increasing order of area
ii) in the order of length and if lengths are same, in the order of breadth
c struct student 6
{
char name[20];
unsigned int p : 8;
unsigned int c : 8;
unsigned int m : 8;
unsigned int b : 8;
};
typedef struct student student_t;
SRN
student_t find_highest(const student_t s[], int n)
{
// TODO
}
The student structure holds the name and the marks in subjects p, c, m and b. The last 4 are stored in
bitfields to save space.
Complete the function to find the student with the total highest score.
d An array has 0s and 1s and has been sorted. Write a function to find the rightmost 0 using the concept 6
of binary search.
5 a Find the outputs or undefined behavior when the following block is executed. 6
{
int a = 10;
int *p = &a;
int b = 20;
{
int a = 30; int c = 50;
printf("%d %d %d\n", a, b, *p);
p = &c; b = c;
}
printf("%d %d %d\n", a, b, *p);
}
b You are given a file in.dat which has a few integers. 5
Write a program to process this file, read the integer values and write them back in reverse to a file
called out.dat. Example: if in.dat contains the following
in.dat : 10 40 20 50 30
then when the program is executed, the out.dat should contain
out.dat: 30 50 30 40 10
c #define mul(x, y) x * y 2+2+
#define MAX 10 1
#define MIN 5
#define TEMP MAX + MIN
int main()
{
printf(“val : %d\n”, mul(MAX + 1, MIN – 1));
#define MAX 20
printf(“val : %d\n”, mul((MAX + 1), MIN – 1));
printf(“temp : %d\n”, TEMP);
}
d This file x.c is compiled as follows. 4
$ gcc x.c -o x
int main(int argc, char* argv[])
{
// has some code
}
and is run as
$ ./x we love all
i) what type is argv[0] and what is its value?
ii) What are the values of argc and argv[argc]?
SRN