pointers in c++

#include <iostream>

using namespace std;

int main()
{
   int x=5;
   int *ptr=&x;
   cout<<&x<<endl;        //prints the address of the variable (x)
   cout<<ptr<<endl;       //prints the address of the variable (x)
   cout<<*ptr<<endl;      //prints the value of x(5)
   cout<<&ptr<<endl;      //prints the address of the pointer (ptr)
   
   
}

pointers in c++

/*
Here is how pointers work in a nustshell(represent | as what's
happening in the memory and / as a place in the ram):
int x = 2; | 2/0x00ef5
int *z = &x| 0x00ef5/0x00ef6 (See how the value of the pointer z
matches with the memory address of x? that's how they work!)

when you print out the pointer as *n (replace n with the var name)
it will actually look at the value
see it's a memory address
go to that memory address
and print the value originally in the memory address which is 2

Here is code:
*/
int x = 5;
int *y = &x;
cout << *y+1;
/*
the reason why i did *y+1 was so to show that after it got
the value from the memory address it will add 1
*/

c++ pointers and functions

#include <iostream>

using namespace std;

void increment(int *n){  		//declare argument of the functon as pointer
    *n+=1;
   cout<<"In function: "<<*n<<endl; 
}

int main()
{
   int x=5;			
   increment(&x);		//passing the address of the variable to the function
   cout<<"In main: "<<x<<endl;
   
}

why do we use pointers in c++

//why do we use pointers:
1)pass values by refrence to a function
2)return multiple values from a function
3)use pointers in combinational with arrays
4)dynamic memory allocation
5)use pointers in a base class in order to access object of derived class (Smart pointers)

Pointers in c++

int x = 2;
int *y = &x;

cout << *y;

pointer to pointer c++

#include <iostream>
using namespace std;

struct Distance {
    int feet;
    float inch;
};

int main() {
    Distance *ptr, d;

    ptr = &d;
    
    cout << "Enter feet: ";
    cin >> (*ptr).feet;
    cout << "Enter inch: ";
    cin >> (*ptr).inch;
 
    cout << "Displaying information." << endl;
    cout << "Distance = " << (*ptr).feet << " feet " << (*ptr).inch << " inches";

    return 0;
}

C++相关代码片段

how to kill

hello world cpp

cpp hello world

when kotlin

how to write hello world c++

fenwick tree

main function

python loop

is palindrom

subsequence

insertion sort

react cookie

data structure

Stack Modified

increment integer

496. Next Greater Element I.cpp

c++ freecodecamp course 10 hours youtube

simple interest rate

deliberation meaning

fingerprint

c++ system() from variable

operator using

unambiguous

Stream Overloading

quick_sort

hash table

graph colouring

the question for me

fname from FString

how togreper

is plaindrome

logisch oder

robot framework for loop example

spyder enviroment

pallindrome string

ue4 c++ string from fvector

interactive problem

two sum solution

interpolation search

Required Length

new expression

Targon lol

xor linked list

stack implementation

typescript

loop through array

loop array

how to point to next array using pointer c++

file exist

floating point exception

array di struct

castin in C++

varint index

how to make a instagram report bot python

windows servis from console app

add integers

listas enlazadas/ linked lists

niet werkend

bubble sort

triangle angle sum

divisor summation

rotateArray

destiny child

Populating Next Right Pointers in Each Node

cosnt cast

bucket sort

double plus overload

Z-function

binary search

permutation

linked list

Implicit conversion casting

square root

public method

tower of hanoi

selection sort

dangling pointer

hello world programming

statements

volumeof a sphere