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.

Priyanka said:   1 decade ago
@shiva

How can it leads to segmentation fault?

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

Wikiok said:   1 decade ago
In Win7/GCC it runs, no crash.
But if the compiler set x to NULL in the definition line, then it will crash.

Shiva said:   1 decade ago
there is no way to assign a constant to pointer directly.it cause segmentation fault.

Tim said:   1 decade ago
Obviously, on most machines, this will cause a crash. That was not one of the choices.


Post your comments here:

Your comments will be displayed after verification.