Day#59 'C' Coding Challenge

Day#59 'C' Coding Challenge

What is the output of the below code?

include<stdio.h> #define NULL 2 void main() { int a; a = NULL; printf("%d",a); }

----------------------------------------------------------------

In the above code, a preprocessor directive is used to define constant NULL as 2.
The same has been used below in the code and is assigned to a. 
The output of the code is 2.
  • Even though the above code is valid, is not best practice to re-define NULL.
  • NULL is a pre-defined constant whose value is used across the code for different purposes
  • NULL is not a keyword and if used in code as variable doesn't throw any error
  • NULL is assigned value of Zero internally.
  • NULL is used for assigning default (Zero) value to pointer, terminate the strings

Post a Comment

0 Comments