Open In App

ASCII NULL, ASCII 0 (‘0’) and Numeric literal 0

Improve
Improve
Like Article
Like
Save
Share
Report

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';
 
    // Display the values
    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'; // Initialize a char variable with the null character
    unsigned int integer = 0; // Initialize an unsigned int variable with the value 0
    char charBinary = '0'; // Initialize a char variable with the character '0'
 
    // Display the values
    printf("charNULL: %c\n", charNULL); // Print the value of charNULL as a character
    printf("integer: %u\n", integer);   // Print the value of integer as an unsigned integer
    printf("charBinary: %c\n", charBinary); // Print the value of charBinary as a character
 
    return 0;
}


Java




public class Main {
    public static void main(String[] args) {
        char charNULL = '\0';
        int integer = 0;
        char charBinary = '0';
 
        // Display the values
        System.out.println("charNULL: " + charNULL);
        System.out.println("integer: " + integer);
        System.out.println("charBinary: " + charBinary);
    }
}


Javascript




// JavaScript program to demonstrate values of different data types
 
// Initialize variables
let charNULL = '\0';
let integer = 0;
let charBinary = '0';
 
// Display the values
console.log("charNULL: " + charNULL);
console.log("integer: " + integer);
console.log("charBinary: " + charBinary);


Python3




# Python code equivalent to the C++ program
 
# Define variables
charNULL = '\0'
integer = 0
charBinary = '0'
 
# Display the values
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
Previous
Next
Share your thoughts in the comments
Similar Reads