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 1 of 3.
J.Joel said:
3 years ago
In pointer, the size of int is 4 and the size of string is 1.
So, sizeof(NULL) defines the integer.
size("") is a string because of double courts, also it does not contain any value.
So, sizeof(NULL) defines the integer.
size("") is a string because of double courts, also it does not contain any value.
(1)
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)
Jakir said:
1 decade ago
#include<stdio.h>
int main()
{
printf("%d, %d\n", sizeof(NULL), sizeof(""));
return 0;
}
I got output as 8 1.
64-bit machine.
int main()
{
printf("%d, %d\n", sizeof(NULL), sizeof(""));
return 0;
}
I got output as 8 1.
64-bit machine.
(1)
Anjaneyareddy said:
1 decade ago
@Shraddha.
Here 4, 1 is the correct answer because of sizeof ("") --->sizeof ("\0").
So it will take an one bit value. So it will be print 1 and sizeof (NULL) ----> sizeof (null\0).
n->0.
u->1.
l->2.
l->3 and \0->4.
So the output will become into 4 and 1.
Here 4, 1 is the correct answer because of sizeof ("") --->sizeof ("\0").
So it will take an one bit value. So it will be print 1 and sizeof (NULL) ----> sizeof (null\0).
n->0.
u->1.
l->2.
l->3 and \0->4.
So the output will become into 4 and 1.
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 "".
Mohan said:
6 years ago
sizeof("") => 1 => because every string in c ended with '\0'(internally) whether it may have characters or not.
sizeof(NULL) =>4 or 2 machine dependent => because NULL is MACRO which is replaced as 0 there fore sizeof(0) = sizeof(int) => integer size may be 2 in turbo c and 4 in GCC compiler.
sizeof(NULL) =>4 or 2 machine dependent => because NULL is MACRO which is replaced as 0 there fore sizeof(0) = sizeof(int) => integer size may be 2 in turbo c and 4 in GCC compiler.
Sheheryar izhar said:
7 years ago
Pointer size in 2 bytes in 16 bits.
Lakshmi Priya said:
7 years ago
Output is 4, 2 because " " is string not character.
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers