C Programming - Pointers - Discussion
Discussion Forum : Pointers - Find Output of Program (Q.No. 9)
9.
What will be the output of the program if the size of pointer is 4-bytes?
#include<stdio.h>
int main()
{
printf("%d, %d\n", sizeof(NULL), sizeof(""));
return 0;
}
Answer: Option
Explanation:
In TurboC, the output will be 2, 1 because the size of the pointer is 2 bytes in 16-bit platform.
But in Linux, the output will be 4, 1 because the size of the pointer is 4 bytes.
This difference is due to the platform dependency of C compiler.
Discussion:
27 comments Page 2 of 3.
Pooja said:
5 years ago
NULL is Predefine macro i.e. #define NULL (void*) 0 which is pointer and size of a pointer is 4B and " " space is character and size of char is 1B.
(1)
Ramya reddy said:
1 decade ago
As null is a null pointer and size of all pointers is same and is given 4 its size is 4 and sizeof "" is 1 since it is an empty string with '\0'.
Pranoti Patil said:
8 years ago
The Size of pointer on 16- bit compiler is 2 bytes.
The Size of pointer on 32- bit compiler is 4 bytes.
The Size of blank character is 1 byte.
The Size of pointer on 32- bit compiler is 4 bytes.
The Size of blank character is 1 byte.
TDas said:
5 years ago
Answer should be 4, 2 because in " " there is a blank and a Null character. To make it 4, 1 there should not be any blank so, it should be "".
Poornachandra HD said:
8 years ago
The size differs for 32 and 64-bit system.
In 32-bit, It will be 4 bytes.
In 64-bit, It will be 8 bytes.
In 32-bit, It will be 4 bytes.
In 64-bit, It will be 8 bytes.
Mahesh said:
1 decade ago
O/P is depends on compiler:
If you run using Dev C++ then o/p: 8, 1.
Linux compiler o/p: 4, 1.
If you run using Dev C++ then o/p: 8, 1.
Linux compiler o/p: 4, 1.
Anchal said:
1 decade ago
@Anjaneyareddy.
If you say so for NULL then the sizeof ("") - - >sizeof ("\0").
\0->0?
If you say so for NULL then the sizeof ("") - - >sizeof ("\0").
\0->0?
Siya said:
9 years ago
I can't understand it please explain with an example of sizeof (NULL);.
Purushotham said:
1 decade ago
Here null is act as a pointer? can expalin any one please.
Shraddha said:
1 decade ago
Is the answer is 4, 2 or 4, 1? Can anyone explain it?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers