Chapter - 16: Miscellaneous Features

Point out the error, if any, in the following programs:


B
Sections
1
Exercises

A

B

C

1

(a)

#include<stdio.h>
int main()
{
	typedef struct patient
	{
		char name[20];
		int age;
		int systolic_bp;
		int diastolic_bp;
	}ptt;
	ptt p1 = { "anil", 23, 110, 220 };
	printf("%s %d\n", p1.name, p1.age);
	printf("%d %d\n", p1.systolic_bp, p1.diastolic_bp);
	return 0;
}

Error: No error. There's no error, 'typedef' makes 'struct patieny' so that, we can use ptt direct as a simple variable, and there's no need to use 'struct patient' whenever we declare any variable of type 'patient'.


(b)

#include<stdio.h>
void show();
int main()
{
	void(*s)();
	s = show;
	(*s)();
	s();
	return 0;
}
void show()
{
	printf("don't show off. It won't pay in the long run\n");
}

Error: There are two methods to invoke a function, (*func)(); func();


(c)

#include<stdio.h>
void show(int, float);
int main()
{
	void(*s)(int, float);
	s = show;
	(*s)(10, 3.14);
	return 0;
}
void show(int i, float f)
{
	printf("%d %f\n", i, f);
}

Error: No error,output is 10 3.14


© 2020 Garbage Valuegarbage value logo