β

C++ Code Snippets

Blog of GangMax 13 阅读
c++

From here .

#include <iostream>

int main()
{
    using namespace std;
    cout << "Hello, world!" << endl;
    return 0;
}
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
     system("echo -n '\nHostname: '"); system("hostname");
     system("echo -n '\nIP Address: '"); system("ip a");
     system("echo -n '\nDate/Time: '"); system("date");
     system("echo '\nFilesystem Utilization:'"); system("df -h; echo");
     return 0;
}
#include <iostream>
#include <unistd.h>
using namespace std;
int main()
{
        pid_t PID,CPID;
        PID = getpid();
        CPID = fork();
        if(CPID<0)
        {       cout << "Error starting child process\n";
                return 1;
        }
        else
        {
                cout << "The PID of the current process: " << PID << endl;
                cout << "The PID of the new child process: " << CPID << endl;
        }
        return 0;
}
#include <iostream>
#include <unistd.h>
using namespace std;
int main()
{
        pid_t PID,CPID;
        PID = getpid();
        CPID = fork();
        if(CPID<0)
        {       cout << "Error starting child process\n";
                return 1;
        }
        else
        {
                cout << "The PID of the current process: " << PID << endl;
                cout << "The PID of the new child process: " << CPID << endl;
        }
        return 0;
}
#include <iostream>
#include <unistd.h>
using namespace std;
int main()
{
        int myAge = 40;

        int* agePtr = &myAge;

        cout << "Address of pointer is pointing " << agePtr << endl;

        cout << "Address of pointer " << &agePtr << endl;
        cout << "Data at memory address " << *agePtr << endl;


        int** agePtrPtr = &agePtr;

        cout << "agePtr " << *agePtrPtr << endl;

        cout << "Data " << **agePtrPtr << endl;

  int* nullPtr = 0;

  cout << "Data " << *nullPtr << endl;

        return 0;
}
c++
作者:Blog of GangMax
原文地址:C++ Code Snippets, 感谢原作者分享。

发表评论