Different Ways To Write Zero In C - Teaching
Maybe your like
| Updated: 2003-01-19 05:50 |
| Different Ways to Write Zero in C Last revised: Sunday January 19, 2003 05:50. Please be clear on the different ways of saying "zero" in C: 0 is a C integer with the value 0 '\0' is a C char const containing the null character, value 0 NULL is a define for the null pointer, value 0 FALSE is a define or enum Boolean, value 0All these things are zero. (NULL and FALSE must be defined by you; the other two are native to C.) I'll also mention that the official ASCII 3-letter name for the character '\0' is NUL (not NULL), so you might prefer to use a #define to make NUL equivalent to '\0' and use NUL in your code instead of '\0'. Which one of these zeroes you use should depend on the context in your code where you use it. Don't confuse the zeroes and the contexts. Given these declarations: typedef enum { FALSE=0, TRUE } Boolean; #define NULL 0 /* usually done in <stdio.h> */ int i; char *ptr; Boolean truth; char ch;This is correct and easy to read: i = 0; ptr = NULL; truth = FALSE; ch = '\0';The following generates exactly the same code (the code itself is "correct"); but, writing code like this is misleading and bad style: i = NULL; /* BAD: i is an integer, not a pointer */ ptr = '\0'; /* BAD: ptr is a pointer, not a char */ ch = FALSE; /* BAD: ch is a char, not a Boolean */ truth = 0; /* BAD: truth is a Boolean, not an int */The compiler does not care about which form of zero you use. Use the form of zero that tells the human reader of your program what type of data you are using. Do not mislead your readers by using the wrong form of zero in the wrong program context.
Last revised: Sunday January 19, 2003 05:50. Email comments to Ian! D. Allen [email protected] |
|
Web Author: Ian! D. Allen [email protected] Updated: 2003-01-19 05:50
|
Tag » What Is 0 In C
-
What Is \0 In C Language And What Is It's Use? (with Example Please).
-
Objective C - What Does \0 Stand For? - Stack Overflow
-
What Is Use Of \0 In The C Programming Language? - Quora
-
How Does The -'0' And +'0' Work In C? - DaniWeb
-
Difference Between NULL Pointer, Null Character ('') And '0' In C With ...
-
What Does Return 0 Do In C? - Linux Hint
-
C Programming Course Notes - Decisions And Branching
-
What Is The Use Of A '\0' Character In C Language? - Youth4work
-
C : Value Of An Integer N Is 1,0 And -1 For The Value Of M - W3resource
-
ERR30-C. Take Care When Reading Errno
-
C Logical Operators | Microsoft Learn
-
C Isdigit() - C Standard Library - Programiz
-
NULL Pointer V/s Null Character ('\0') V/s '0' In C - CodesDope