Question 1: Which data type is NULL in c Programming Language?
Question 2: What is the output of the below program?
#include<stdio.h> #define NULL 0 void main() { printf("%d",sizeof(NULL)); }
---------------------------------------------------------------------
NULL is not a variable in C. It is a predefined constant without any data type associated. It has a value of Zero.
The definition of NULL is as follows:
#define NULL ((void *)0)
A NULL can be defined in the program and can be compiled without any error. However, considering that it is pre-defined, it is preferable not to re-define NULL.
The statement printf("%d",sizeof(NULL)); prints the sizeof NULL (which holds the integer value) and hence size of integer shall be printed which is 4 bytes (either in 32-bit or 64-bit system)
0 Comments