Chapter - 6: Functions And Pointers

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


F
Sections
1
Exercises

A

B

C

D

E

F

G

1

(a)

#include<stdio.h>
float circle(int);
int main()
{
	float area ;
	int radius = 1 ;
	area = circle ( radius ) ;
	printf ( "\n%f", area ) ; 
	return 0;
}
float circle(int r)
{
	float a;
	a = 3.14*r*r;
	return a;
}

Output: 3.1400


(b)

#include<stdio.h>
int main()
{
	void slogan( ) ;
	int c = 5 ;
	c = slogan( ) ;
	printf ( "\n%d", c ) ;  
	return 0;
}
void slogan()
{
	printf ( "\nOnly He men use C!" ) ;
}

Error: slogan cannot be assigned to any variable, as it has a return type of void.


(c)

#include<stdio.h>
void fun(int, int);
int main()
{
	int i = 5, j = 2;
	fun( i, j ) ;
	printf ( "\n%d %d", i, j ) ; 
	return 0;
}
void fun(int i, int j)
{
	i = i * i ;
	j = j * j ; 
}

Output: 5 2


(d)

#include<stdio.h>
void fun(int *, int *);
int main()
{
	int i = 5, j = 2 ;
	fun( &i, &j ) ;
	printf ( "\n%d %d", i, j ) ; 
	return 0;
}
void fun(int *i, int *j)
{
	*i = *i * *i ;
	*j = *j * *j ; 
}

Output: 25 4


(e)

#include<stdio.h>
int main()
{
	float a = 13.5 ;
	float *b, *c ;
	b = &a ; /* suppose address of a is 1006 */ 
	c = b ;
	printf ( "\n%u %u %u", &a, b, c ) ;
	printf ( "\n%f %f %f %f %f", a, *(&a), *&a, *b, *c ) ; 
	return 0;
}

Output:

1006 1006 1006
13.5 13.5 13.5 13.5 13.5


#include<stdio.h>
#include<stdlib.h> //It is not given in question, so assumed.
int main()
{
	int i = 0;
	i++;
	if(i <= 5)
	{
		printf("C adds wings to your thoughts\n");
		exit(0);
		main();
	}
	return 0;
}

Output: C adds wings to your thoughts.


© 2020 Garbage Valuegarbage value logo