C Programming - Pointers - Discussion

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

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

Sangee said:   1 decade ago
Error :invalid conversion from void* to int *.

Srini said:   1 decade ago
Is void used to store only data? I can't understood.

Mahesh said:   1 decade ago
No error in DOS also. I checked it.

A jain said:   1 decade ago
No error in gcc.

Mohanty said:   1 decade ago
Is void valid only for pointer value?

Because if I change it to a normal variable it shows-.

Error: "variable or field declared void".

Datta said:   1 decade ago
Turbo c compiler can run this program because there is not check this program,but in borland c or Visual studio will have error.we can not use 2nd time void pointer without typecast.

Lohitha said:   1 decade ago
Here we've declared 'p2' as the void pointer, which meaning it can refer to any kind of data type.

we've refered it to an integer pointer as well as the referance of integer variable to pointing to the void pointer.

Is program is legal.

Satyam said:   1 decade ago
Should be converted like for integer (*((int *) voidpointervariable)

Sundar said:   1 decade ago
In Turbo C there is no warning or error on compilation.

But in GCC, it shows the following error:

Error: invalid conversion from 'void*' to 'int*'.

This is due to platform dependency. GCC is a modern compiler while comparing to the typical Turbo C.
(1)

Sonal said:   1 decade ago
No @badusa, its not like that, void means anything; it can store any data of any type.

Compiler can only follow the instruction & there is no warning.


Post your comments here:

Your comments will be displayed after verification.