Give a brief note on null pointer assignment. Write a program in ‘C’ to illustrate this concept. 6m Jun2008
Null Pointer Assignment
It does make sense to assign an integer value to a pointer variable. An exception is an assignment of 0, which is sometimes used to indicate some special condition. A macro is used to represent a null pointer. That macro goes under the name NULL. Thus, setting the value of a pointer using the NULL, as with an assignment statement such as ptr = NULL, tells that the pointer has become a null pointer. Similarly, as one can test the condition for an integer value as zero or not, like if (i == 0), as well we can test the condition for a null pointer using if (ptr == NULL) or you can even set a pointer to NULL to indicate that it’s no longer in use. Let us see an example given below.
Example
# include<stdio.h>
# define NULL 0
main()
{
int *pi = NULL;
printf(“The value of pi is %u”, pi);
}
OUTPUT
The value of pi is 0
4(a) Write a program which reads a file and counts the number of lines and words in the file, assuming that a line can contain at most 80 characters. 8m
Solved program can be found on this link http://cssimplified.com/c-programming/write-a-program-in-c-language-that-accepts-the-name-of-a-file-as-input-and-prints-those-lines-of-the-file-which-have-the-word-this-10m-dec2007