Rabu, 17 Desember 2025

listing4.5.cpp Analyzing the Null Terminator in a C-Style String

//listing4.5.cpp
#include <iostream>
using namespace std;

int main()
{
    char sayHello[]={'H','e','l','l','o',' ','W','o','r','l','d','\0'};
    cout << sayHello << endl;
    cout << "Size of array: " << sizeof(sayHello) << endl;

    cout << "Replacing space with null" << endl;
    sayHello[5]='\0';
    cout << sayHello << endl;
    cout << "Size of array: " << sizeof(sayHello) << endl;

    return 0;
}

output:
 
Hello World
Size of array: 12
Replacing space with null
Hello
Size of array: 12

Process returned 0 (0x0)   execution time : 0.408 s
Press any key to continue.

Tidak ada komentar:

Posting Komentar