C Programming - Pointers - Discussion

Discussion Forum : Pointers - Point Out Errors (Q.No. 1)
1.
Point out the compile time error in the program given below.
#include<stdio.h>

int main()
{
    int *x;
    *x=100;
    return 0;
}
Error: invalid assignment for x
Error: suspicious pointer conversion
No error
None of above
Answer: Option
Explanation:
While reading the code there is no error, but upon running the program having an unitialised variable can cause the program to crash (Null pointer assignment).
Discussion:
15 comments Page 2 of 2.

Prudhvi sai said:   6 years ago
It's a segmentation fault. It's point to a garbage value.

Thilagavathi said:   1 decade ago
Is it possible to assign a value directly to a pointer.

Swapnil said:   8 years ago
There will be a segmentation fault.

Right @Shiva.

Priyanka said:   1 decade ago
@shiva

How can it leads to segmentation fault?

Rohini said:   1 decade ago
@Shiva.

There is no segmentation fault.


Post your comments here:

Your comments will be displayed after verification.