C Programming - Floating Point Issues - Discussion

Discussion Forum : Floating Point Issues - Find Output of Program (Q.No. 2)
2.
What will be the output of the program?
#include<stdio.h>
int main()
{
    float *p;
    printf("%d\n", sizeof(p));
    return 0;
}
2 in 16bit compiler, 4 in 32bit compiler
4 in 16bit compiler, 2 in 32bit compiler
4 in 16bit compiler, 4 in 32bit compiler
2 in 16bit compiler, 2 in 32bit compiler
Answer: Option
Explanation:

sizeof(x) returns the size of x in bytes.
float *p is a pointer to a float.

In 16 bit compiler, the pointer size is always 2 bytes.
In 32 bit compiler, the pointer size is always 4 bytes.

Discussion:
3 comments Page 1 of 1.

Sachin said:   1 decade ago
Is it size always 2 byte irrespective of data type?

Hemanth said:   1 decade ago
Yes irrespective of datatype the default size of any pointer is 2 in 16 bit compiler, 4 in 32 bit compiler and 8 in 64 bit compiler.

Saket baghel said:   1 decade ago
Because pointers hold the address which will be INTEGER always not float so its indeed sizeof(int).

Post your comments here:

Your comments will be displayed after verification.