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?
#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;
}
#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;
}
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);
}
}
using System;
class MainClass {
public static void Main (string[] args) {
// Declaring variables
char charNULL = '\0'; // Character variable initialized with null character
uint integer = 0; // Unsigned integer variable initialized with 0
char charBinary = '0'; // Character variable initialized with character '0'
// Displaying the values
Console.WriteLine("charNULL: " + charNULL); // Printing the value of charNULL
Console.WriteLine("integer: " + integer); // Printing the value of integer
Console.WriteLine("charBinary: " + charBinary); // Printing the value of charBinary
}
}
// 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);
# 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.
Contact Us