Skip to content

Latest commit

 

History

History
65 lines (46 loc) · 1.26 KB

File metadata and controls

65 lines (46 loc) · 1.26 KB
title layout nav_order parent
Source code and Git repository
default
2
Home

Instructions

Development environment

Just once!!!!

git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"
sudo apt-get install build-essential clang-format

Hello world

  1. Create the file pointers.cpp and paste the following code:
#include <iostream>

using namespace std;

int main() {
    int x = 10;
    int* p = &x; // Pointer to x

    cout << "Value of x: " << x << endl; // Output: 10
    cout << "Address of x: " << &x << endl; // Output: Address of x
    cout << "Value at pointer p: " << *p << endl; // Output: 10
    cout << "Address stored in pointer p: " << p << endl; // Output: Address of x

    *p = 20; // Change value at pointer p

    cout << "New value of x: " << x << endl; // Output: 20
    return 0;
}
  1. Open a terminal (Ctrl-ñ) and compile the file:
g++ -std=c++20 -o pointers pointers.cpp

This will create the file pointers (the executable!). To run it:

./pointers