What is the output of following code:
#include <stdio.h>
main()
{
char *p = 0;
*p = 'a';
printf("value in pointer p is %c\n", *p);
}
Answers
Code :
Input :
#include <stdio.h>
main()
{
char *p = 0;
*p = 'a';
printf("value in pointer p is %c\n", *p);
}
Output :
$ cc pgm.c
$ a.out
Segmentation fault (core dumped)
About Run Time Error :
❋ This program has run time error.
❋ The error seen oftenly while a program is executed.
❋ A pop - up menu will come that will show that the program has run time error
❋ This error will be resolved after 10 - 15 seconds.
Explanation:
i think many of the compilers will give an error or may your program will be crash bcz first of all you must initilize a pointer variable ,which points a valid memory location.
******here,char *p=0(i.e,p is a null pointer)null pointer means a pointer variable doesn’t contain of any valid memory location of memory block.
your prog may crash or error
if:-1)assigning value to uninitilized pointer{int *P,m=100;*p=m;}
2)assigning value to a pointer variable{int *p,m=100;p=m;}…….