C Programming - Pointers - Discussion

Discussion Forum : Pointers - Yes / No Questions (Q.No. 5)
Will the following program give any warning on compilation in TurboC (under DOS)?

int main()
    int *p1, i=25;
    void *p2;
    return 0;
Answer: Option
No answer description is available. Let's discuss.
21 comments Page 1 of 3.

Mohammad Shabaz said:   3 years ago
Why can't we use Arithmetic on void pointers?

Srisailam said:   7 years ago
In GCC compiler showing no error and no output.

Raj said:   7 years ago
Please explain it.

Aarzu said:   8 years ago
What is use of void pointer?

Divya said:   8 years ago
It's impossible.

DjRahul said:   9 years ago
But we didn't typecast it and still we are using it how?

Kariyappa said:   1 decade ago
No error, because void pointer can take any datatype.

Anshu said:   1 decade ago
This program will not give any error or warning on gcc compiler until and unless we will not try to print p2 value.

But if we try to print p2 value it will give an error such as:

Warning: dereferencing 'void *' pointer
Error: invalid use of void expression.

So solve this this kind of error,we need to typecast the void pointer.
Such as:

printf("value of p2 is %d

Thank you.

Tanvi said:   1 decade ago
It is compiling on Turbo C. Ideally it should not as yes, arithmetic cannot be performed on Void Pointer.

Diksh said:   1 decade ago
I agreed with sonal.

Post your comments here:

Your comments will be displayed after verification.