ASCII NULL, ASCII 0 (‘0’) and Numeric literal 0
The ASCII (American Standard Code for Information Interchange) NULL and zero are represented as 0x00 and 0x30 respectively. An ASCII NULL character serves as a sentinel character of strings in C/C++. When the programmer uses ‘0’ in his code, it will be represented as 0x30 in hex form.
What will be filled in the binary integer representation in the following program?
C++
#include <iostream>
int main() {
char charNULL = '\0' ;
unsigned int integer = 0;
char charBinary = '0' ;
std::cout << "charNULL: " << charNULL << std::endl;
std::cout << "integer: " << integer << std::endl;
std::cout << "charBinary: " << charBinary << std::endl;
return 0;
}
|
c
#include <stdio.h>
int main() {
char charNULL = '\0' ;
unsigned int integer = 0;
char charBinary = '0' ;
printf ( "charNULL: %c\n" , charNULL);
printf ( "integer: %u\n" , integer);
printf ( "charBinary: %c\n" , charBinary);
return 0;
}
|
Java
public class Main {
public static void main(String[] args) {
char charNULL = '\0' ;
int integer = 0 ;
char charBinary = '0' ;
System.out.println( "charNULL: " + charNULL);
System.out.println( "integer: " + integer);
System.out.println( "charBinary: " + charBinary);
}
}
|
Javascript
let charNULL = '\0' ;
let integer = 0;
let charBinary = '0' ;
console.log( "charNULL: " + charNULL);
console.log( "integer: " + integer);
console.log( "charBinary: " + charBinary);
|
Python3
charNULL = '\0'
integer = 0
charBinary = '0'
print ( "charNULL:" ,charNULL)
print ( "integer:" , integer)
print ( "charBinary:" , charBinary)
|
The binary form of charNULL will have all its bits set to logic 0. The binary form of an integer will have all its bits set to logic 0, which means each byte will be filled with a NULL character (\ 0). The binary form of charBinary will be set to the binary equivalent of hex 0x30.
Last Updated :
09 Mar, 2024
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...