Chapter - 7: Data Types Revisited

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


B
Sections
1
Exercises

(a)

#include<stdio.h>
int main()
{
	long num;
	num = 2;
	printf("\n%ld", num);
	return 0;
}
Error: No error

(b)
#include<stdio.h>
int main()
{
	char ch = 200;
	printf("\n%d", ch);
	return 0;
}

Error: No error


(b)

#include<stdio.h>
int main()
{
	char ch = 200;
	printf("\n%d", ch);
	return 0;
}

Error: No error but a warning, as we are saving an integer to a char type variable, it just truncates that value and store.


(c)

#include<stdio.h>
int main()
{
	unsigned a = 25;
	long unsigned b = 25l;
	printf("\n%lu %u", a, b);
	return 0;
}

Error: No error


(d)

#include<stdio.h>
int main()
{
	long float a = 25.345e454;
	unsigned double b = 25;
	printf("\n%lf %d", a, b);
	return 0;
}

Error: a double cannot be unsigned, and a warning that value of float is out of range.


(e)

#include<stdio.h>
int main()
{
	float a = 25.345;
	float *b;
	b = &a;
	printf("\n%f %u", a, b);
	return 0;
}

Error: No error


(f)

#include<stdio.h>
static int y;
int main()
{
	static int z;
	printf("%d %d", y, z);
	return 0;
}

Error: No error


© 2021 Garbage Valuegarbage value logo